1

如果没有登录帐户,我正在尝试加载 viewController 但是它给了我这个错误Warning: Attempt to present <DefaultViewController: 0xb96cac0> on <MainViewController: 0xb95c320> whose view is not in the window hierarchy! 这是我现在正在使用的代码:

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

}
4

2 回答 2

1

DefaultViewController通过在 appDElegate 中导入来试试这个。

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
DefaultViewController *viewController = [[DefaultViewController alloc] init];
self.window.rootViewController = viewController;
[self.window makeKeyAndVisible];
于 2013-08-23T06:54:38.353 回答
1

实际上这是从 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];
于 2013-08-23T06:40:38.307 回答