[英]UITableViewController section header and footer no showing
Swift 3,XCode 8.3動態原型單元格。 該視圖(類CustomTableViewController: UITableViewController
)位於一個單獨的情節提要中,該情節提要從另一個情節提要中引用,並帶有一個表的序列,該表本身已嵌入到Nav Controller中。
實現了以下方法:
override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat
override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat
override func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView?
override func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int)
如果我在navcontroller嵌入視圖-控制, viewForFooterInSection
將調用和查看是可見的。 willDisplayHeaderView
仍然沒有被調用。 編輯 :這不是嵌入它正在將我的CustomTableViewController設置為初始視圖控制器。 當Nav Controller為IVC時,則調用viewForFooterInSection,而當CustomTableViewController(嵌入Nav Controller)為IVC時,則不調用viewForFooterInSection。
如果我將表格更改為靜態單元格, willDisplayHeaderView
調用viewForFooterInSection
並將調用viewForFooterInSection
,但僅當將視圖嵌入到Nav Controller中時,才會再次調用。
我試圖避免將其嵌入到另一個導航控制器中,但是無論如何都不會調用willDisplayHeaderView
。
您忘記了這些代表:
override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 100
}
override func tableView(_ tableView: UITableView, estimatedHeightForFooterInSection section: Int) -> CGFloat {
return 100
}
標頭也一樣。 編碼愉快!
為添加代理方法
如果在Viewcontroller中使用表,請檢查將Delegate和數據源分配給表。
您可以實現表視圖的以下方法
extension DemoViewController: UITableViewDelegate {
//setting header height to 100
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 100
}
//setting footer height to 100
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 100
}
//setting header view
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let headerView = UIView(frame: CGRect(x:0, y:0, width: tableView.frame.size.width, height: 50))
headerView.backgroundColor = UIColor.red
return headerView
}
//setting footer view
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
let footerView = UIView(frame: CGRect(x:0, y:0, width: tableView.frame.size.width, height: 50))
footerView.backgroundColor = UIColor.green
return footerView
}
func tableView(_ tableView: UITableView, willDisplayFooterView view: UIView, forSection section: Int) {
//customization for footer goes here
}
func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
//customization for header goes here
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.