为什么在应用程序中显示UIAlertView:didFinishLaunchingWithOptions:导致错误?

在我的应用程序的第一次运行时,我显示一个警报视图,供用户selectiCloud或本地文档存储。 显示警报视图导致以下错误:

应用程序启动结束时,应用程序预期具有根视图控制器wait_fences:无法接收回复: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与故事板。 根视图控制器在故事板中设置。

尝试将[alert show]replace为:

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

这延迟了一次通过runloop的警报,大概是让你的应用程序的控制器和故事板完成他们的设置之前,提醒警报。

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

在您的应用程序到达didFinishLaunchingWithOptions之前:它需要设置一个rootViewController。 你可以为一个名为viewController的ViewController设置这个属性:

  self.window.rootViewController = self.viewController; 

请注意,将控制器设置为rootViewController会自动添加视图。 所以,你不需要再添加视图:

 [self setViewController:];