我想使用另一个用户界面将一个单元格添加到我的表格 View 的最后一行。代码是这样的。
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell:JoinCell = tableView.dequeueReusableCellWithIdentifier(reuseIdentifier, forIndexPath: indexPath) as! JoinCell
let lastSectionIndex = tableView.numberOfSections-1
let lastSectionLastRow = tableView.numberOfRowsInSection(lastSectionIndex) - 1
let lastIndexPath = NSIndexPath(forRow:lastSectionLastRow, inSection: lastSectionIndex)
let cellIndexPath = tableView.indexPathForCell(cell)
if cellIndexPath == lastIndexPath {
cell = tableView.dequeueReusableCellWithIdentifier("JoinFooterCell") as! JoinFooterCell
}
我收到错误消息“无法将类型‘JoinFooterCell’的值分配给类型‘JoinCell’”
有人可以给我建议吗?谢谢。
最佳答案
执行此操作并为 datasource.sections.count
使用您在 numberOfSectionInTableView()
和 datasource.rows.count
中返回的相同值使用您在 numberOfRowsForSection()
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if datasource.sections.count - 1 == indexPath.section && datasource.rows.count - 1 == indexPath.row {
let cell = tableView.dequeueReusableCellWithIdentifier("JoinFooterCell") as! JoinFooterCell
return cell
} else {
let cell = tableView.dequeueReusableCellWithIdentifier(reuseIdentifier, forIndexPath: indexPath) as! JoinCell
return cell
}
}
关于ios swift uitableview 添加最后一个单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39030514/