我想根据奇偶indexPath
加载Identifier。
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
if indexPath.row % 2 == 0{
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! categoryTVC
return cell
}else{
let cell = tableView.dequeueReusableCellWithIdentifier("CellOdd", forIndexPath: indexPath) as! categoryTVC
return cell
}
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.categoryDetailArray?.count ?? 00
}
这项工作但有一个问题..它每次都会生成一个额外的单元格。
最佳答案
您的代码是正确的。但是你应该记住,如果你想要相同数量的奇数和偶数单元格,那么你应该有偶数个单元格。 因此,您必须在 numberOfRowsInSection 方法中提供 24 或 26(偶数行)而不是 25(奇数行)。
关于ios - 具有两个标识符的表格 View 单元格。对于 TableView 中的奇数一个单元格和甚至另一个单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38734934/