URL方案无法打开视图

时间:2015-02-27 18:51:08

标签: ios

我正在尝试实现一个自定义URL Scheme,其中一个特定的URL(myapp:// article)打开文章视图。我虽然没有取得任何成功。

通常,应用会按照故事板中的定义打开LoginViewController。对于URL Scheme,我这样做:

-(BOOL)application:(UIApplication *)application
           openURL:(NSURL *)url
 sourceApplication:(NSString *)sourceApplication
        annotation:(id)annotation{

    if ([[PocketAPI sharedAPI] handleOpenURL:url]) {
        NSLog(@"Login complete!");
        return YES;
    } else {
        NSLog(@"url recieved: %@", url);
        NSLog(@"scheme: %@", [url scheme]);
        NSLog(@"query string: %@", [url query]);
        NSLog(@"host: %@", [url host]);

        if ([[url host] isEqualToString: @"article"]) {
            Stream *stream = [[Stream alloc] initWithDictionary:data];

            UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];

            ArticleViewController *articleViewController = [storyboard instantiateViewControllerWithIdentifier:@"ArticleViewController"];

            articleViewController.stream = stream;

            [self.window makeKeyAndVisible];
            [self.window.rootViewController presentViewController:articleViewController animated:YES completion:NULL];
            return YES;
        }
        return YES;
    }
}

我不断获得Warning: Attempt to present <ArticleViewController: 0x79040cb0> on <LoginViewController: 0x7906f8c0> whose view is not in the window hierarchy!

我做错了什么?

1 个答案:

答案 0 :(得分:0)

在实例化视图控制器之前,请先尝试显示窗口。在实例化窗口之前,主视图控制器确实不在视图层次结构中(因为还没有)。