2013-08-25 18 views
0

我學ObjC程序流,到目前爲止我明白鏈在main.m-> UIApplicationMain-> AppDelegate-開始>的ViewController哪種方法被調用時appdelegate.m將控制轉移到的viewController

我不點不明白的是ViewController中的哪個方法將AppDelegate類傳遞的焦點...

我覺得理解這個主題是至關重要的,所以要感謝任何澄清。

我Appdelegate.m的驗證碼 -

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:  (NSDictionary *)launchOptions 
{ 
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
// Override point for customization after application launch. 

MasterViewController *masterViewController = [[MasterViewController alloc] init]; 
self.navigationController = [[UINavigationController alloc] initWithRootViewController: masterViewController]; 
self.window.rootViewController = self.navigationController; 
[self.window makeKeyAndVisible]; 
return YES; 

和視圖控制器裏面有這些方法 -

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
if (self) { 
    // Custom initialization 
} 
return self; 
} 

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
[self.navigationController setNavigationBarHidden:YES animated: NO]; 
} 

- (void)viewWillAppear:(BOOL)animated 
{ 
[super viewWillAppear: animated]; 
} 

和其他方法...

我的問題是

  1. 要什麼方法AppDelegate在MasterViewController中傳輸控制。在MasterViewController「完成」它的工作之後,控件是否會回來?還是隻是循環?
  2. MasterViewController如何獲取廈門國際銀行名稱初始化(是相同的名稱爲M的文件,即它是什麼意思 - nibNameOrNil包:nibBundleOrNil)
  3. 我看到導航控制器的參與,但我不明白是怎麼回事連接的viewController ....

如果你明白我的誤解點 - 請耐心解釋......我覺得這一點後,我就可以開始...

回答

0

(1)你正在以程序化的方式思考邏輯流程。主運行循環沿應答器鏈調度事件。你的MasterViewController並不真正「完成」。

(2)UIViewController的指定初始值爲initWithNibName:bundle:。您在這裏使用init將不會觸及任何關聯的nib文件。如果你想從筆尖初始化MasterViewController,那麼你必須使用指定的初始化工具,例如

MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:@"your-nib-name-goes-here" bundle:nil];

nibNameOrNilnibBundleOrNil是剛纔的方法參數名稱。這對你來說可能是零。看看documentation這個方法在這些參數爲零時的行爲。

(3)UINavigationControllerUIViewController的一個子類,它以分層方式呈現內容。在這種情況下,應用程序的窗口的根視圖控制器是一個導航控制器。反過來,該導航控制器的根視圖控制器就是您的MasterViewController實例。

對於UINavigationController描述得很好。

+0

謝謝你的回答。如果我理解你的話,這個範圍什麼都不做?(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if(self){ //定製初始化 } return self; } – Ilan

+0

儘管在應用程序的委託中實例化MasterViewController時,您應該使用指定的初始化程序'-initWithNibName:bundle:',現在您只需調用'init'。 – FluffulousChimp

相關問題