2011-05-16 41 views
0

我想了解爲什麼我的應用程序沒有離開主體(啓動)。 我認爲這條線是原因。我的代碼沒有離開主體

int retVal = UIApplicationMain(argc, argv, nil , nil); 

的源代碼:

#import <UIKit/UIKit.h> 

int main(int argc, char *argv[]) 
{ 
    printf("I'm in main"); 

    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 

    printf("\nafter the autiorealeas pool"); 

    int retVal = UIApplicationMain(argc, argv, nil , nil); 

    printf("\nbefore the [pool relase] call"); 

    [pool release]; 
    printf("Leaving main"); 
    return retVal; 
} 
+3

別擔心!這就是它應該是... :) – 2011-05-16 05:31:48

回答

5

這是正確的 - 它不會返回! according to the Apple docs

返回值

即使被指定的整數返回類型,這個函數永遠不會返回。當用戶通過按下主頁按鈕退出iPhone應用程序時,應用程序將移動到後臺。

+0

除了printf()調用這是默認模板。我甚至不必爲了我的應用程序而啓動main。 – lampShade 2011-05-16 05:33:12

+0

沒錯,你沒有。對函數「UIApplicationMain()」的調用開始主UIKit runloop,從中你的應用程序不會退出,直到它終止。你不需要爲普通的UIKit應用程序觸摸'main()'函數。 – 2011-05-16 07:29:53

相關問題