ios swift uitableview 添加最后一个单元格

标签 ios swift tableview

我想使用另一个用户界面将一个单元格添加到我的表格 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/

相关文章:

java - 快速将字符串转换为数据库 HTTP.UTF8

swift - 有没有办法使用用 swift 编写的 cocoapod?

ios - 带有 CoreData 的水平 UICollectionView

ios - 选择段时如何从 TableView 加载选定数据?

ios - 尝试使用 searchDisplayController 将自定义 BackgroundView 设置为 UITableView,导致消息发送到已释放的实例

android - 应用内结算到期

ios - 通过 Relay Server 连接 iOS App SAP-SUP

ios - 如何更正这个程序的错误

Swift:在原始 GameScene 上加载新的 SKScene? (仍然保留 GameScene 在下面?)

swift - 将数组数据加载到 TableView 中