2015-12-02 62 views
4

我已經覆蓋moreNavigationController tableview,但我想使用默認爲本機moreNavigationController的tableview數據源(tabbaritem圖標,名稱和徽章等)相同的行。 我試圖從現有的數據源中獲取單元格。以下是我的代碼片段:自定義moreNavigationController的tableview和類似的用戶界面

func tabBarController(tabBarController: UITabBarController, shouldSelectViewController viewController: UIViewController) -> Bool 
{ 
    if (viewController == tabBarController.moreNavigationController && tabBarController.moreNavigationController.delegate == nil) 
    { 
     if tabBarController.moreNavigationController.topViewController?.view is UITableView 
     { 
      let view:UITableView = tabBarController.moreNavigationController.topViewController?.view as! UITableView 

      tblDataSource = view.dataSource 

      view.delegate = self 

      view.dataSource = self 
     } 
    } 

    return true 
} 


func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell 
{ 

    let cell:UITableViewCell = tblDataSource?.tableView(tableView, cellForRowAtIndexPath: indexPath) 
    return cell 
} 

但是,它顯示我空白單元格。

+0

你是什麼意思「moreNavigationControlle」是什麼意思? –

+0

如果UITabviewController包含多於五個選項卡,則moreNavigationController是第五個選項卡ViewController。請參閱https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITabBarController_Class/#//apple_ref/occ/instp/UITabBarController/moreNavigationController –

+0

您的問題可以通過對問題的額外描述來完成。 – andrewbuilder

回答

0

好吧,我不明白。 如果你需要與native相同的行,那你爲什麼要重寫UITableViewDataSource方法?保持原樣。覆蓋您需要的必要方法。

+0

我需要一個選項卡的shouldSelectViewController的返回值爲false。這就是爲什麼我必須重寫它。 –

1

您需要實現以下方法來正確顯示細胞「更多」視圖控制器:

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) { 
    tblDataSource?.tableView!(tableView, willDisplay: cell, forRowAt: indexPath) 
}