2012-01-27 78 views
2

在我的应用程序的第一次运行中,我向用户显示警报视图以选择iCloud或本地文档存储。显示警报视图导致以下错误:为什么在应用程序中显示UIAlertView:didFinishLaunchingWithOptions:导致错误?

Applications are expected to have a root view controller at the end of application launch wait_fences: failed to receive reply: 10004003

这究竟是为什么?你如何在启动时显示警报视图而不会出现此错误?

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    // Check the user preferences for document storage options 
    if (![UserPreferencesHelper userDocumentStoragePreferencesHaveBeenCreated]) 
    { 
     // User preferences have not been set, prompt the user to choose either iCloud or Local data storage 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Use iCloud?" 
                 message:@"Would you like to store data in iCloud?" 
                 delegate:self 
               cancelButtonTitle:nil 
               otherButtonTitles:@"No", @"Yes", nil]; 
     [alert show]; 
    } 
} 

**更新**

我要指出,我使用的是iOS 5的故事板。根视图控制器在故事板中设置。

回答

7

尝试用替换[alert show]

[alert performSelector:@selector(show) withObject:nil afterDelay:0.0]; 

这延迟了单次警报通过runloop,想必让你的应用程序的控制器和故事板,以在警报出现之前完成其设置。

+0

Darren,谢谢!这很有效=)。我在这个墙上撞了一会儿头...... – 2012-01-27 23:00:07

2

就像它说的,你需要一个根控制器为你的应用程序。警报显示在正常的控制器管理的视图上方,因此您需要一个控制器管理的视图才能显示在上方。

+0

hm,我在故事板中设置了我的rootview控制器。所以我想你现在说的是,当调用applicationDidFinishLaunchingWithOptions时,rootview控制器还没有被创建。正确? – 2012-01-27 22:39:31

+0

没错,听起来像某种地方布线搞砸了。不是一个答案,但也许表明在哪里看? (对不起,我不知道故事板的任何内容。) – smparkes 2012-01-27 22:42:20

0

在您的应用程序到达didFinishLaunchingWithOptions之前:它需要设置一个rootViewController。您可以为命名的viewController与视图控制器设置该属性:

self.window.rootViewController = self.viewController; 

请注意,设置一个控制器作为RootViewController的自动添加视图。所以,你不需要有再次添加视图:

[self setViewController:]; 
+0

AtkinsonCM,我相信他们用iOS5中的故事板改变了这一点。我应该在我原来的帖子中提到这一点。我会更新它... – 2012-01-27 22:45:15

相关问题