J.D*_*Doe 8 uitableview ios swift
我正在尝试将自定义页脚设置为我的表格视图.我在一个nib文件上创建了页脚并创建了一个受控制的页脚.
class LoginTableFooter: UITableViewHeaderFooterView
Run Code Online (Sandbox Code Playgroud)
在viewDidLoad()我写这个代码
let footerNib = UINib(nibName: "LoginTableFooter", bundle: nil)
tableView.register(footerNib, forHeaderFooterViewReuseIdentifier: "LoginTableFooter")
Run Code Online (Sandbox Code Playgroud)
然后我实施了 viewForFooterInSection
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
let cell = self.tableView.dequeueReusableHeaderFooterView(withIdentifier: "LoginTableFooter")
let header = cell as! LoginTableFooter
return cell
}
Run Code Online (Sandbox Code Playgroud)
viewForFooterInSection从未被称为.我也试图实现,viewForHeaderInSection但它也没有被调用.你知道出了什么问题吗?我的表视图中只有一个部分; 是否可以/更好地直接设置页脚viewDidLoad?
Kru*_*nal 12
实现 - 为您的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
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19901 次 |
| 最近记录: |