2012-01-27 81 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

相關問題