2017-07-24 58 views
1

Swift 3,XCode 8.3 動態原型單元格。該視圖(類CustomTableViewController: UITableViewController)位於一個單獨的故事板中,該故事板從另一個故事板中引用,其中一個表格自身嵌入導航控制器中。UITableViewController部分頁眉和頁腳不顯示

以下方法實現:

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時,當CustomTableViewController(嵌入在Nav Controller中)是IVC時,viewForFooterInSection被調用,viewForFooterInSection不被調用。

如果我將表格更改爲靜態單元格,willDisplayHeaderView將被調用,並且viewForFooterInSection將被調用,但只有在視圖嵌入到導航控制器中時纔會再次調用。

嵌入另一個導航控制器有副作用,我試圖避免,但在任何情況下willDisplayHeaderView不會被調用。

+0

下列方法這與實現無關的框架的內部錯誤。實施必需的方法。這不是問題。 – kos

回答

0

你忘了這些代表:

override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { 
    return 100 
} 

override func tableView(_ tableView: UITableView, estimatedHeightForFooterInSection section: Int) -> CGFloat { 
    return 100 
} 

同爲標題。快樂的編碼!

0

添加

  1. 高度爲標題的委託方法(返回爲標題適當的高度)
  2. 信息查看頭
  3. 高度爲頁腳(返回爲頁腳適當的高度)
  4. 信息查看頁腳

檢查如果您在Viewcontrolle內使用表,則將委託和數據源分配給表河

+0

它的一個類CustomTableViewController:UITableViewController ...是委託正確分配。至少viewForFooterInSection被嵌入到導航控制器中時被調用... – kos

0

您可以實現表視圖

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 
} 
} 
+0

我以爲我明確表示這些方法是實現的,但viewForFooterInSection在沒有嵌入到導航控制器時不會被調用。當爲單元使用動態原型時,不會調用willDisplayXXXX。 – kos