2012-12-22 30 views
-1

我開始學習objective-c和ios編程。我有兩個名爲MainViewController和GameViewController的視圖控制器,在我的項目中也有兩個xib文件。我將xib文件與ViewController連接起來。完全下面是我的文件:確定哪個UIViewController先運行

視圖控制器,

AppDelegate.h 
    AppDelegate.m 
    MainViewController.h 
    MainViewController.m 
    GameViewController.h 
    GameViewController.m 

和xibs,

Main.xib 
    Game.xib 

我選擇Main.xib在主界面項目options.I'm試圖理解下面的問題,當我運行這個應用程序第一main.m runs.Thats好吧。

之後,AppDelegate類是否運行?xcode如何確定哪個View Controller首先運行?

當我運行這個項目時,只有黑屏。任何人都可以幫助我瞭解ios應用程序的運行順序嗎?

+0

無關的Xcode的。 – 2012-12-22 22:44:28

回答

3

的Xcode沒有確定什麼,這完全取決於你

-application:didFinishLaunchingWithOptions:launchOptions 

由系統調用後設置您的UI。下面是其中ExampleViewController首先被初始化的一個示例:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    // Override point for customization after application launch. 
    self.viewController = [[ExampleViewController alloc] initWithNibName:@"ExampleViewController" bundle:nil]; 
    self.window.rootViewController = self.viewController; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 

中的應用初始化流程爲:

main() -> AppDelegate (or whatever class has been designated the delegate) -> initial view controller 
+0

在這個例子中,你需要導入CRViewController.Am我是吧? – saidozcan

+0

這是僞代碼,但是。你的應用程序是空白的,因爲你沒有初始化視圖控制器。 – CodaFi

+0

如果確定是什麼? if(UI_USER_INTERFACE_IDIOM()== UIUserInterfaceIdiomPad) – saidozcan