2011-01-19 9 views
0

私はUINavigationControllerのルートコントローラとしてのUIViewControllerを追加していますが、これを行うとUINavigationControllersナビゲーションバーへのUIViewController navigationItemsの関係?

UIViewController *myUIViewController = [[TableController alloc] init]; 
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:myUIViewController]; 

私の質問はのUIViewController

[[self navigationItem]setTitle:@"Name"]; 

にnavigationItemプロパティを設定することに関するものである(下記参照)何UIViewControllerでこれを設定する方法と、UINavigationControllerによってどのように取得されるかの関係です。私の理解は、ナビゲーションバーは、UINavigationController上にあると私は間違ってそこに設定しようとしています。

UINavigtionControllersのナビゲーションバーは、タイトルを取得するためにUIViewControllerのnavigationItemを参照していますか?私はこれらの2人が一緒に働いている方法について、ちょっと不思議です。

答えて

2

はい、-initWithRootViewController:などで発生します。UINavigationControllerは、ナビゲーションスタック内のUIViewControllerオブジェクト全体を繰り返し処理し、それぞれのプロパティを自身に割り当てます。このような

何かがボンネットの下に起こっている:

for(UIViewController *vc in viewControllers) { 
    [vc setNavigationController:self]; 
    //set other properties here as well... 
} 
関連する問題