ios – 代码不在窗口层次结构根视图中
发布时间:2020-12-14 19:15:56 所属栏目:百科 来源:网络整理
导读:参见英文答案 Attempt to present UIViewController on UIViewController whose view is not in the window hierarchy????????????????????????????????????26个 我在尝试链接我的UIViewController时遇到了问题,但我收到了最后的错误. Attempt to present Vi
参见英文答案 >
Attempt to present UIViewController on UIViewController whose view is not in the window hierarchy????????????????????????????????????26个
我在尝试链接我的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! 解决方法
看起来你的UIViewController(Login)不在Window Hierarchy中.
您可能正在将UIViewController添加为UIWindow中的子视图. AppDelegate.m - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { //Other code parts [self.window setRootViewController:loginViewController]; return YES; } 要么 如果要在任何UIViewController(比如FirstViewController)中将LoginViewController的视图添加为subView,请改为显示它 在你的FirstViewController.m中, -(void)viewDidLoad{ [super viewDidLoad]; LoginViewController *loginViewController ;//Instantiate LoginViewController here [self presentViewController:loginViewController animated:NO completion:Nil]; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |