ios - 如何使页脚 UITableViewCell 不是静态的?

标签 ios swift uitableview

enter image description here

我有 2 个原型(prototype)动态单元格,分别称为 InvoiceDetailCell 和 TotalCostFooterCell。我使用 viewForFooterInSection 将 TotalCostFooterCell 作为页脚单元格 View 。这是我用来将数据分配给 UITableView 的代码

这是我在 UITableViewController 中的代码。

extension InvoiceDetailVC : UITableViewDataSource {
    // MARK: - UI Table View Datasource Methods

    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }

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

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "InvoiceDetailCell", for: indexPath) as! InvoiceDetailCell
        cell.invoiceElementData = invoiceElements[indexPath.row]

        return cell
    }



}


extension InvoiceDetailVC : UITableViewDelegate {

    // MARK: - UI Table View Delegate Methods

    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        let cell = tableView.dequeueReusableCell(withIdentifier: "invoiceDetailFooterCell") as! TotalCostFooterCell
        cell.totalCost = singleInvoiceData.unpaid

        return cell
    }

}

但结果并不如我所料,我的意思是页脚单元格处于固定状态/未移动。这是 .gif 文件:http://g.recordit.co/vf0iwCfEWX.gif

您可以看到总成本(红色)是固定的/静态的,我希望页脚单元格可以滚动并始终位于底部。还是我没有实现我想要的东西?

enter image description here

最佳答案

使表格样式分组

有两种方式:

  1. viewDidLoad() 中执行 tableView.style = .grouped
  2. 从 Storyboard中选择 TableView ,然后在属性检查器中将样式更改为分组。请引用附图。 enter image description here

关于ios - 如何使页脚 UITableViewCell 不是静态的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50481352/

相关文章:

ios - 按照技术问答 QA1625 重命名应用程序失败

ios - RLMException,对象类型需要迁移

swift - 将 alpha 设置回 1.0 后,不会重新出现任何按钮/标签/任何内容

ios - 当有多个部分时, TableView 是黑色的

ios - 在 UICollectionView 中以编程方式选择项目

ios - 如何使用 iOS 与 Web 服务器交互,而不使用 WebView

ios - Swift - 映射到不同的类型

swift - Metal 中的 ASTC 纹理压缩——我应该使用什么作为每行的字节数?

ios - 可折叠表格 View 错误

ios - 是否可以在 UITableView 中有主标题、副标题和 UITableViewStyleValue1 样式标题