【发布时间】:2017-02-24 17:27:30
【问题描述】:
正如标题所说,我想在 tableView 中创建一个不变的单元格,其中单元格是可变的。我希望这个牢房是最后一个。实际上,我所有的单元格都是用来自 Firbase 的数据创建的。最后一个常数单元应始终存在。感谢您的帮助。
【问题讨论】:
标签: swift xcode uitableview cell
正如标题所说,我想在 tableView 中创建一个不变的单元格,其中单元格是可变的。我希望这个牢房是最后一个。实际上,我所有的单元格都是用来自 Firbase 的数据创建的。最后一个常数单元应始终存在。感谢您的帮助。
【问题讨论】:
标签: swift xcode uitableview cell
你可以试试这样的:
您只能更改某个 indexPath 处的单元格(在您的情况下为最后一个),然后按照您的意愿进行设置。
这是一个例子:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if ((indexPath as NSIndexPath).row == 8 {
let cell = tableView.dequeueReusableCell(withIdentifier: "lastCell", for: indexPath) as! lastCellClass
//your code
return cell
}else{
let cell = tableView.dequeueReusableCell(withIdentifier: "dataCell", for: indexPath) as! dataCellClass
//your code
return cell
}
}
不要忘记从零开始的单元格(indexPath.row 8)是第 9 个单元格。
注意:如果您的 numberOfRows 可以更改,您可以这样做:
if ((indexPath as NSIndexPath).row == (yourData.count - 1){
//Here you will get your last cell
}
【讨论】:
Value of type 'UICollectionView' has no member 'dequeueReusableCell'
是的,您可以通过多种方式实现它。
这是我的方法。我将为它创建新的 tableview 部分。我将始终保持行数不变。 在 indexpath 的行单元格中,我将检查该部分的条件并返回相应的常量单元格。
【讨论】: