简体   繁体   English

View Controller不在App Delegate中显示

[英]View Controller not presenting from App Delegate

I am trying to load a viewController if there are no accounts logged in however it gives me this error Warning: Attempt to present <DefaultViewController: 0xb96cac0> on <MainViewController: 0xb95c320> whose view is not in the window hierarchy! 我正在尝试加载没有登录帐户的viewController,但是它给了我这个错误Warning: Attempt to present <DefaultViewController: 0xb96cac0> on <MainViewController: 0xb95c320> whose view is not in the window hierarchy! Here is the code that I am using right now: 这是我现在正在使用的代码:

BOOL returnAllOff = [[User data] returnAllOff];

if (returnAllOff) {
    DefaultViewController *viewController =[[DefaultViewController alloc]
    init];
    UIViewController *presentingController = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
    [presentingController presentViewController:viewController animated:YES completion:nil];

}

Actually this is the correct way of loading a ViewController from AppDelegate.. 实际上,这是从AppDelegate加载ViewController的正确方法。

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    DefaultViewController *viewController = [[DefaultViewController alloc] initWithNibName:@"DefaultViewController" bundle:nil];
    self.window.rootViewController = viewController;
    [self.window makeKeyAndVisible];

Try this one by importing DefaultViewController in appDElegate. 通过在appDElegate中导入DefaultViewController来尝试这一操作。

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
DefaultViewController *viewController = [[DefaultViewController alloc] init];
self.window.rootViewController = viewController;
[self.window makeKeyAndVisible];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM