2015-12-02 61 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) 
}