ios – 使用Swift设置自定义表格视图页脚
2019年05月03日
作者:佚名
我正在尝试将自定义页脚设置为我的表格视图.我在一个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设置自定义表格视图页脚所遇到的程序开发问题。
如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。