HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 使用Swift设置自定义表格视图页脚大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试将自定义页脚设置为我的表格视图.我在一个nib文件上创建了页脚并创建了一个受控制的页脚.
class LoginTableFooter: UITableViewHeaderFooterView

在viewDidLoad()中我写了这段代码

let footerNib = UINib(nibName: "LoginTableFooter",bundle: nil)
        tableView.register(footerNib,forHeaderFooterViewReusEIDentifier: "LoginTableFooter")

然后我实现了viewForFooterInSection

func tableView(_ tableView: UITableView,viewForFooterInSection section: int) -> UIView? {
    let cell = self.tableView.dequeueReusableHeaderFooterView(withIdentifier: "LoginTableFooter")
    let header = cell as! LoginTableFooter

    return cell
}

从未调用viewForFooterInSection.我也试图实现viewForHeaderInSection但它也没有被调用.你知道出了什么问题吗?我的表视图中只有一个部分;是否可以/更好地直接在viewDidLoad上设置页脚?

解决方法

实施 – 代表和您的tableview的数据源并设置两者 – heightForFooterInSection& viewForFooterInSection
tableView.delegate = self
tableView.datasource = self

// set view for footer
func tableView(_ tableView: UITableView,viewForFooterInSection section: int) -> UIView? {
    let footerView = UIView(frame: CGRect(x: 0,y: 0,width: tableView.frame.size.width,height: 40))
    footerView.BACkgroundColor = UIColor.blue
    return footerView
}

// set height for footer
func tableView(_ tableView: UITableView,heightForFooterInSection section: int) -> CGFloat {
    return 40
}

大佬总结

以上是大佬教程为你收集整理的ios – 使用Swift设置自定义表格视图页脚全部内容,希望文章能够帮你解决ios – 使用Swift设置自定义表格视图页脚所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。