Finding the rootViewController in iOS

后端 未结 3 1937
北荒
北荒 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 08:04

    This worked for me:

    UIViewController * rootViewController = (UIViewController *)[[[UIApplication.sharedApplication.keyWindow subviews] firstObject];
    

提交回复
热议问题