Attempt to present * on * whose view is not in the window hierarchy

前端 未结 7 1229
半阙折子戏
半阙折子戏 2020-11-30 05:29

I\'m trying to make a modal view controller in my app delegate (I created a function called showLoginView). But whenever I try to call it I get a warning in XCode:



        
7条回答
  •  忘掉有多难
    2020-11-30 06:08

    UIViewController *activeController = [UIApplication sharedApplication].keyWindow.rootViewController;
    if ([activeController isKindOfClass:[UINavigationController class]])
    {
       activeController = [(UINavigationController*) activeController visibleViewController];
    }
    else if (activeController.modalViewController)
    {
        activeController = activeController.modalViewController;
    }
    [activeController presentModalViewController:vc animated:YES];
    

提交回复
热议问题