如何通过在 Swift 的 TableView 中使用页脚来上传部分下的标签?

How do I can upload label under the sections by using footer in the TableView in the Swift?

计算器流。

我知道那些页脚可能*有很多方法可以在单元格下方制作标签作为已知页脚。

我知道如何使用 index.row 创建页脚,它允许您使用数组自动添加标题、图像和所有内容,否则页脚就不行吗?

我正在尝试在iOS13中设置样式等部分下制作标题。

资源代码:

当您创建数组以提供自动单元格时。

class SettingViewController: UIViewController {

  var settingtitle = ["Item1", "Item2", "Item3"]

  var footerTitle = ["Footer1", Footer2", Footer3"]

  @IBOutlet weak var TableView: UITableView!

}

现在是使用委托和数据源构建 UITableView 的时候了。

extension SettingViewController: UITableViewDelegate, UITableViewDataSource {

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

}

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

 let cells = TableView.dequeueReusableCell(withIdentifier: "Cells", for: indexPath) as? SettingTableViewCell

 cells?.Setting_Title.text = settingtitle[indexPath.row]

 return cells!
 }
}

但是我如何使用数组上传下方单元格中的标签?

我尝试了很多解决堆栈溢出的方法,但我注意到其中一种方法有效,但它显示在整个单元格的一个页脚下。

感谢您帮助解决这个问题。 如果你知道,请告诉我。

实现这个方法:

func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
    return footerTitle[section]
}

=== 已编辑 ===

如果要为每个单元格设置页脚:

  func numberOfSections(in tableView: UITableView) -> Int {
    return settingtitle.count
}

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

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

    let cells = TableView.dequeueReusableCell(withIdentifier: "Cells", for: indexPath) as? SettingTableViewCell
    cells?.Setting_Title.text = settingtitle[indexPath.section]
    return cells!
}

func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
    return footerTitle[section]
}

第一组代表:
TableView.delegate = 自己

然后添加以下方法: func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? { 让 footerView = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.size.width, height: 100)) footerView.backgroundColor =.绿色

return footerView

}