UIViewController *topRootViewController = [UIApplication sharedApplication].keyWindow.rootViewController; while (topRootViewController.presentedViewController) { topRootViewController = topRootViewController.presentedViewController; } //[topRootViewController presentViewController:yourController animated:YES completion:nil]; //or [topRootViewController myMethod];
解決辦法2:html
UIStoryboard *mainstoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; LoginViewController* loginViewController = [mainstoryboard instantiateViewControllerWithIdentifier:@"LoginViewController"]; [self.window makeKeyAndVisible]; //[LoginViewController presentViewController:yourController animated:YES completion:nil]; //or [LoginViewController myMethod];
IOS 開發中 Whose view is not in the window hierarchy 錯誤的解決辦法
原文地址:http://www.cnblogs.com/xunziji/p/4025009.htmlspa