詳解 IOS 7.1 程式啟動原理

來源:互聯網
上載者:User

標籤:color   使用   os   io   檔案   for   ar   cti   

程式都是從Main方法入口的 IOS 也不例外

int main(int argc,char * argv[])

{

    @autoreleasepool {

        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));

    }

}

在IOS 裡main 方法裡有個UIApplicationMain裡面帶有4個參數

param 1: argc : 對應argv的參數數量

param 2: argv:    參數變數列表 (載入應用程式對應的-info.plist檔案資訊)

param 3: 指定UIApplication類或子類的名稱。如果為nil預設就是UIApplication

param 4: 設定應用程式的代理對象。  如果是nil,則從應用程式的主nib檔案載入的代理對象。

傳回值: 這個方法一般不會返回,即使使用者點擊了IOS的home按鈕,程式會把它移動到後台當中。

程式正常退出時,UIApplicationMain函數才返回

 

當程式啟動完成後會來到AppDelegate,它繼承UIResponder並遵循了UIApplicationDelegate

UIResponder:定義了響應和處理事件的介面,它是UIApplication、UIWindow、UIView的父類能夠接收使用者的運動事件和觸摸事件

// 程式啟動完成

(BOOL)application:(UIApplication *)applicationdidFinishLaunchingWithOptions:(NSDictionary *)launchOptions

// 程式失去交點

(void)applicationWillResignActive:(UIApplication *)application

// 程式進入後台

 (void)applicationDidEnterBackground:(UIApplication *)application
// 程式進入前台

 (void)applicationWillEnterForeground:(UIApplication *)application

// 程式擷取焦點

(void)applicationDidBecomeActive:(UIApplication *)application

// 程式即將關閉

 (void)applicationWillTerminate:(UIApplication *)application

 

 

 

如果程式沒有設定主要的啟動storyboard檔案,而且也沒有在

(BOOL)application:(UIApplication *)applicationdidFinishLaunchingWithOptions:(NSDictionary *)launchOptions

方法裡設定window對象是不能進行正常活動

通常在此方法裡設定

(BOOL)application:(UIApplication *)applicationdidFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

self.window = [[UIWindowalloc]initWithFrame:[[UIScreenmainScreen]bounds]];

self.window.backgroundColor = [UIColorwhiteColor];

self.viewController =[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] ;

 // 設定根視圖控制器

self.window.rootViewController =self.viewController;

 // 設定主視圖並可見  視窗只有一個主視圖

 [self.windowmakeKeyAndVisible];

 }

 至此有了window對象後就能夠在上面添加各種View進行自訂介面了

 反之沒有window對象 就看不見任何UI介面

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.