2017-07-02 32 views
0

內自定義的UITableView細胞我有一個UITableviewController這是我在Swift4編程方式創建。 enter image description here一個UITableViewController頁腳

圖中的顯着矩形是我footerview與UITableView

override func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? { 

     let tableFooterView = UITableView() 
     tableFooterView.rowHeight = 100 

     return tableFooterView 
    } 

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

我要加載自定義細胞在footerview的實現代碼如下細胞。我嘗試使用這個下面的代碼

tableFooterView.dequeueReusableCell(withIdentifier: emptyCellIdentifier) as! EmptyTableViewCells 

,但我得到的錯誤 -

fatal error: unexpectedly found nil while unwrapping an Optional value

請幫

回答

0

您必須先註冊爲頁腳的tableView細胞,當你正在創建viewForFooterInSection方法和你如果你正在委託和數據源爲selftableFooterView UITableView

應該區分兩者通過標籤或某事的表
tableFooterView.register(EmptyTableViewCells.self, forCellReuseIdentifier: emptyCellIdentifier) 

所以你的方法是:

func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? { 
    if tableView.tag == 1 { 
     tableFooterView = UITableView() 
     tableFooterView.register(EmptyTableViewCells.self, forCellReuseIdentifier: emptyCellIdentifier) 
     tableFooterView.rowHeight = 100 
     tableFooterView.tag = 2 
     tableFooterView.dataSource = self 
     tableFooterView.delegate = self 
     return tableFooterView 
    } else { 
     //footer view is nil for the table view which is in the main table footer 
     return nil 
    } 
} 

這將停止對tableFooterView.dequeueReusableCell線崩潰,但你需要添加其他視圖類似的代碼,而不是IBOutlet中的tableFooter空單元格按鈕和標籤。如果你訪問任何IBOutlet中連接的組件將再次崩潰。

+0

@NasimRony沒有它幫助? –

相關問題