簡體   English   中英

UITableViewController節的頁眉和頁腳未顯示

[英]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
}

標頭也一樣。 編碼愉快!

為添加代理方法

  1. 標頭的高度(返回標頭的適當高度)
  2. 查看標題
  3. 頁腳高度(返回適當的頁腳高度)
  4. 查看頁腳

如果在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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM