Finding the rootViewController in iOS

后端 未结 3 1928
北荒
北荒 2021-02-14 07:31

In ShareKit, the code needs to determine where the rootViewController is so it can show a modal view. For some reason, the code is failing in iOS 5:

    // Try t         


        
3条回答
  •  执笔经年
    2021-02-14 07:42

    I'm not sure if you can rely on window.rootViewController b/c you don't have to set it. You can just add a subview to the window. The following seemed to work fine:

    id rootVC = [[[[[UIApplication sharedApplication] keyWindow] subviews] objectAtIndex:0] nextResponder];
    

提交回复
热议问题