我在尝试关联UIViewController
时遇到问题,但我收到了最后的错误。
Attempt to present ViewController whose view is not in the window hierarchy
这是我的代码:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:@"Wokay"])
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"Vibes"];
[self.window.rootViewController presentViewController:vc animated:YES completion:nil];
}
}
代码错误:
Warning: Attempt to present <ViewController: 0x110634bc0> on <Login: 0x10951e7f0> whose view is not in the window hierarchy!
答案 0 :(得分:2)
您的UIViewController
(Login
)似乎不在窗口层次结构中。
您可能会在UIWindow中添加LoginViewController
作为子视图。
如果是,请将其设置为UIWindow
的{{1}}
<强> AppDelegate.m 强>
rootViewController
或强>
如果要在任何UIViewController(例如- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//Other code parts
[self.window setRootViewController:loginViewController];
return YES;
}
)中将LoginViewController的视图添加为subView,请改为显示
在 FirstViewController.m 中,
FirstViewController