解决方法
如果rootViewController是UIViewController,您可以使用以下代码访问它
UIViewController *rootController=(UIViewController *)((AppDelegate *)[[UIApplication sharedApplication] delegate]).window.rootViewController;
但如果它是UINavigationController,您可以使用下面的代码.
UINavigationController *nav=(UINavigationController *)((AppDelegate *)[[UIApplication sharedApplication] delegate]).window.rootViewController; UIViewController *rootController=(UIViewController *)[nav.viewControllers objectAtIndex:0];