2011-11-01 28 views
5

我最初爲iOS 4開發了我的應用程序,現在iOS 5已經出來,我決定爲iOS 5 SDK開發,現在好像破壞了我的應用程序。Objective-C - 應用程序啓動方法從iOS 4到iOS 5的區別?

我在每個選項卡中都有一個帶有導航控制器的選項卡欄應用程序。

在iOS 4中,啓動後首先執行-application:didFinishLaunchingWithOptions:方法中的所有內容。在執行該方法後,加載第一個選項卡的視圖控制器。

所以,當我登錄我的啓動應用程序(運行的iOS 4.3模擬器),它看起來像這樣:

-[AcandoAppDelegate application:didFinishLaunchingWithOptions:] [Line 35] didFinishLaunchingWithOptions method running 
-[AcandoAppDelegate application:didFinishLaunchingWithOptions:] [Line 60] This should be executed first // And it does as it should 
-[AcandoAppDelegate applicationDidBecomeActive:] [Line 254] applicationDidBecomeActive method running 
-[SeminarsViewController viewDidLoad] [Line 58] 2 - viewDidLoad method running 
-[SeminarsViewController viewDidLoad] [Line 60] This should be executed second // Also as it should 
-[SeminarsViewController viewWillAppear:] [Line 123] 3 - viewWillAppear method running 
-[SeminarsViewController viewDidAppear:] [Line 173] viewDidAppear running 

現在,當我登錄我的啓動應用程序(運行模擬器的iOS 5.0)它看起來像這樣:

-[AcandoAppDelegate application:didFinishLaunchingWithOptions:] [Line 35] didFinishLaunchingWithOptions method running 
-[SeminarsViewController viewDidLoad] [Line 58] 2 - viewDidLoad method running 
-[SeminarsViewController viewDidLoad] [Line 60] This should be executed second // So this should be executed second but is executed first 
-[SeminarsViewController viewWillAppear:] [Line 123] 3 - viewWillAppear method running 
-[AcandoAppDelegate application:didFinishLaunchingWithOptions:] [Line 60] This should be executed first // And this is executed second but should be executed first 
-[AcandoAppDelegate applicationDidBecomeActive:] [Line 254] applicationDidBecomeActive method running 
-[SeminarsViewController viewDidAppear:] [Line 173] viewDidAppear running 

我在這裏丟失了一些明顯的東西嗎?對我來說,看起來我們在iOS 4和iOS 5之間有兩種不同的啓動情況?

+0

如果您多次測試,結果是否相同? –

+0

每次結果都一樣。在iOS 5中處理.xib文件(在我的情況下是MainWindow.xib)與iOS 4相比有什麼不同? –

回答

1

爲什麼成功啓動您的應用程序取決於這些事件的特定順序?在上面的那些序列中應該沒有任何內容會導致您發出問題,您的代碼應該不知道底層啓動順序。

你可以給一些代碼來解釋爲什麼這會導致你的問題?

+0

我在初始化'-application:didFinishLaunchingWithOptions:'方法中的一些對象之前,應該在第一個選項卡中加載視圖控制器(SeminarsViewController)之前對其進行初始化。這就是爲什麼初創公司在iOS 4中「成功」(我的代碼按照它的意圖工作),但是在iOS 5中,完全相同的代碼工作方式不同。因此,他們以某種方式改變了某些內容:「application:didFinishLaunchingWithOptions:'作品從iOS 4到iOS 5. –

+1

啊,好的。我傾向於通過代碼而不是Interface Builder來連接你的視圖控制器,它會讓你完全控制何時創建視圖控制器(以及隨後的視圖加載)。 –

+0

但是,爲什麼我的代碼的行爲有所不同,取決於它是否在iOS 4或iOS 5上運行? –