加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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中的子视图.
如果是这样,请将其设置为UIWindow的rootViewController

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];
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读