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

前端 未结 7 1174
半阙折子戏
半阙折子戏 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:23

    Another reason for that warning can be that you want to present a view controller from an instance which is not the top most view controller.

    So first you have to get the topmost UIViewController and using this instance to call presentViewController:

    UIViewController *root = [UIApplication sharedApplication].keyWindow.rootViewController;
    while (root.presentedViewController) {
        root = root.presentedViewController;
    }
    
    0 讨论(0)
提交回复
热议问题