繁体   English   中英

如何在 UITableView 底部加载第二个 UITableViewCell?

[英]How to load second UITableViewCell at the bottom of UITableView?

我有一个tableView ,它填充我称之为“ TopCell ”的自定义 UITableViewCells。 一切都完美无缺。 但是,我想添加第二个自定义 UITableViewCell 以显示在tableView的底部。 让我们称之为“ BottomCell

我已经创建了BottomCell并连接到它的自定义类。 就像我对“ TopCell ”所做的TopCell

底部单元格将仅显示一次并且位于tableView的底部。

下面是TopCell的基本代码。 那么如何集成BottomCell呢?

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return myData.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    guard let cell = tableView.dequeueReusableCell(withIdentifier: "TopCell", for: indexPath) as? TopCell else { return UITableViewCell() }

    let topVal = indexPath.row + 1
    let noVal = myData[indexPath.row].no ?? 0

    cell.configureCell(top: topVal, no: noVal)
    return cell
}

这是你要求的:

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return myData.count+1
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    if indexPath.row == myData.count {
        guard let cell = tableView.dequeueReusableCell(withIdentifier: "BottomCell", for: indexPath) as? BottomCell else { return UITableViewCell() }

        return cell
    }
    guard let cell = tableView.dequeueReusableCell(withIdentifier: "TopCell", for: indexPath) as? TopCell else { return UITableViewCell() }

    let topVal = indexPath.row + 1
    let noVal = myData[indexPath.row].no ?? 0

    cell.configureCell(top: topVal, no: noVal)
    return cell
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM