ViewDidLoad被调用两次

时间:2015-10-17 20:36:09

标签: ios viewdidload uiwindow

用户成功登录后,我的应用程序。我将调用HOME通知,之后在HomeViewController ViewDidLoad中调用两次。任何人都可以帮忙吗?

  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {      
        //-- Notification Observer
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(HomeNotification:)name:@"HOME"object:nil];

        return YES;
    }

    #pragma mark - Sidemenu & Home
    - (void)HomeNotification:(NSNotification *) notification
    {
        UIStoryboard *sideMenuSB = [UIStoryboard storyboardWithName:SB_SideMenu bundle:[NSBundle mainBundle]];
        SideMenuViewCntrl *sideMenuVC = [sideMenuSB instantiateViewControllerWithIdentifier:VC_SideMenu];

        UIStoryboard *HomeSB = [UIStoryboard storyboardWithName:SB_Home bundle:[NSBundle mainBundle]];
        HomeViewController *homeVC = [HomeSB instantiateViewControllerWithIdentifier:VC_Home];
        UINavigationController *navigationController = [HomeSB instantiateViewControllerWithIdentifier:@"navigationController"];

        MFSideMenuContainerViewController *container = nil;
        if ([[notification name] isEqualToString:@"HOME"])
        {
            container = [MFSideMenuContainerViewController containerWithCenterViewController:homeVC leftMenuViewController:sideMenuVC rightMenuViewController:nil];
        }

 Adding view to window will call viewdidload multiple times?
        [container setLeftMenuViewController:sideMenuVC];
        [container setCenterViewController:navigationController];
        self.window.backgroundColor = [UIColor blackColor];
        self.window.rootViewController = container;
        [self.window makeKeyAndVisible];
    }

1 个答案:

答案 0 :(得分:0)

我在SideMenu容器中添加了两次Home和侧面菜单视图控制器。

container = [MFSideMenuContainerViewController containerWithCenterViewController:homeVC leftMenuViewController:sideMenuVC rightMenuViewController:nil];

删除下面的代码后,现在工作正常....

[container setLeftMenuViewController:sideMenuVC];
[container setCenterViewController:navigationController];