三次调用ViewDidload方法

时间:2016-09-13 19:06:01

标签: ios uinavigationcontroller uistoryboard viewcontroller

我正在使用两个故事板一个Main和另一个Dashboard。 成功回复后,我正在加载LGSideMenu

问题是DashboardViewController ViewDidLoad正在调用3次。

-(void)loadDashboardController{

    dispatch_async(dispatch_get_main_queue(), ^{
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Dashboard" bundle:nil];

        UINavigationController *navigationController = [storyboard instantiateViewControllerWithIdentifier:@"NavigationController"];
        DashboardViewController *mainViewController = [storyboard instantiateInitialViewController];
        mainViewController.rootViewController = navigationController;
        [mainViewController setupWithPresentationStyle:LGSideMenuPresentationStyleSlideAbove type:0];
        UIWindow *window = [UIApplication sharedApplication].delegate.window;
        window.rootViewController = mainViewController;
        [UIView transitionWithView:window
                          duration:0.3
                           options:UIViewAnimationOptionTransitionCrossDissolve
                        animations:nil
                        completion:nil];
    });
}

有人遇到这种问题吗?

1 个答案:

答案 0 :(得分:0)

您只应在应用程序窗口设置rootviewcontroller一次。而已。应该按下其他视图控制器,或者您应该将viewocontrollers设置为navigation controller。所以只设置,

  window.rootViewController = mainViewController;

     //or

  window.rootViewController = navigationcontroller;