从Storyboard实例化UIViewController,未执行viewDidLoad()

时间:2016-05-20 00:49:05

标签: uiviewcontroller uistoryboard

我正在创建一个Slideout导航控制器。

现在我需要分配我的MenuViewController和我的TopViewController。

我在Storyboard中有一个使用其他类型的滑出菜单的TopViewController屏幕。

enter image description here

在我的AppDelegate中,我有以下内容:

let storyboard : UIStoryboard! = UIStoryboard(name: "Main", bundle: nil)
        let dashboard = storyboard.instantiateViewControllerWithIdentifier("DashboardView") as! DashboardViewController

        let menu : SlideoutViewController = SlideoutViewController()
        menu.menuEnabled = true
        menu.topView = dashboard
        menu.menuView = SalesViewController()
        UIApplication.sharedApplication().keyWindow?.rootViewController = menu as SlideoutViewController

但是在执行此操作时,永远不会到达DashboardViewController中的viewDidLoad方法,这意味着该视图尚未实例化。

  

有任何线索吗?

更新:这是幻灯片视图控制器中的函数selectView

func selectView(viewController: UIViewController){

        if (_internalTopNavigation != nil)
        {
            _internalTopNavigation!.removeFromParentViewController();
            _internalTopNavigation!.view.removeFromSuperview();

        }

        _internalTopNavigation = UINavigationController(rootViewController: viewController)
        _internalTopNavigation!.view.frame = CGRect(x: 0, y: 0,
                                                  width: _internalTopView!.view.frame.width,
                                                  height: _internalTopView!.view.frame.height)

        _currentView = viewController;
        _internalTopView!.addChildViewController(_internalTopNavigation!);
        _internalTopView!.view.addSubview(_internalTopNavigation!.view);



        if (_menuEnabled == true)
        {
            viewController.navigationItem.leftBarButtonItem = createMenuButton()
            viewController.navigationItem.leftBarButtonItem!.tintColor = UIColor.blueColor()
        }


        _externalContentView = viewController;


    }

0 个答案:

没有答案