【发布时间】:2018-12-19 00:51:13
【问题描述】:
var mutipleArrayForFirstCell:[String] = ["1","2","3","4","5","6","7","8","9","10"]
var mutipleArrayForSecondCell:[String] = ["11","12","13","14","15","16","17","18","19","20"]
//MARK - TableView delegates
func numberOfSections(in tableView: UITableView) -> Int {
return 2
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if section == 1 {
return mutipleArrayForFirstCell.count
}else {
return mutipleArrayForSecondCell.count
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.row == 0 {
let valueAt1stCell = tableView.dequeueReusableCell(withIdentifier: "FirstCell", for: indexPath) as! multipleCustomCellTableViewCell
valueAt1stCell.Firstlabel.text = mutipleArrayForFirstCell[indexPath.row]
return valueAt1stCell
} else {
let valueAt2ndCell = tableView.dequeueReusableCell(withIdentifier: "SecondCell", for: indexPath) as! SecondCustomTableviewCell
valueAt2ndCell.secondLabel.text = mutipleArrayForSecondCell[indexPath.row]
return valueAt2ndCell
}
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 100
}
我的问题是我想在两个不同的单元格中显示上面声明的两个数组值。我该怎么做??它显示如下:
但它应该在一个单元格中显示 1-10,在另一个单元格中显示 11-20。有人请帮助我,提前谢谢
如何在两个单元格之间留出一些空间?
【问题讨论】:
-
只需将
indexPath.row中的indexPath.section更改为cellForRowAt -
IndexPath 具有节和行值。使用 indexPath.section 值来分隔内容而不是 indexPath.row
-
是的,现在它正在工作@Pratik Prajapati
标签: ios xcode uitableview cocoa-touch swift4