2011-01-19 74 views
0

我加入一個UIViewController作爲根控制器一個UINavigationController(見下文)UIViewController navigationItems與UINavigationControllers導航欄的關係?

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

我的問題是關於設置在UIViewController的

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

的navigationItem財產當你這樣做是什麼是在UIViewController上設置它以及如何由UINavigationController拾取它之間的關係。我的理解是導航欄在UINavigationController上,我錯誤地試圖將它設置在那裏。

UINavigtionControllers導航欄是否會查看UIViewControllers navigationItem以獲取其標題?我只是好奇這兩個人在一起工作的方式。

回答

2

是的,這是-initWithRootViewController:等人發生的情況,UINavigationController遍歷導航堆棧中的所有對象,並將相應的屬性分配給自己。

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

像這樣的事情在引擎蓋下發生