使用moreNavigationController在UITabBarController中为viewControllers设置公共值

时间:2017-09-07 11:21:19

标签: ios uitabbarcontroller

我有'n'ViewControllers,都采用公共变量'cv1',我想在加载控制器之前设置这个cv1。 一切都很好,直到我只设置4个控制器,(即)没有更多标签项。一旦我引入了更多控制器,委托“tabBarController:didSelectViewController”就不会触发UIMoreNavigationController中的模块。

所以我尝试为我的TabBarController类设置UINavigationController委托并处理其他模块tabItem选择,如

func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {

    if navigationController != self.moreNavigationController
    {
        //navigation happening in some other tab Item
        return
    }

    if navigationController.viewControllers.count != 2
    {
        //The first controller of the more tabItem will be MoreViewController, followed by our desired controller in the navigation stack
        return
    }

    guard let selectedController:MyTabItemViewController = self.getTopViewController(from: viewController) else {

        print("***WARNING*** Selected controller doesn't seem to expect  info :\(String(describing: selectedViewController))")
        return

    }

    selectedController.sp = self.sp
    selectedController.sb = self.sb
} 

我能够获取ViewController实例,但在viewDidLoad的{​​{1}}方法之前调用UINavigationController方法,我想在{{1}之前设置变量UI结构和数据提取的方法取决于此变量。

0 个答案:

没有答案