0

在應用程序委託,內部didFinishLaunchingWithOptions功能,我有以下代碼來加載一個觀點,即是一個UINavigationController:的UINavigationController initiWithNibName不從文件的.xib加載設計

UINavigationController *navcon=[[UINavigationController alloc] initWithNibName:@"ThirdView" bundle:[NSBundle mainBundle]]; 

FirstView *fv=[[FirstView alloc] init];

[navcon pushViewController:fv animated:NO]; 

[fv release]; 


[self.window addSubview:navcon.view]; 


[self.window makeKeyAndVisible]; 
return YES; 

的的.xib「ThirdView」,這是一個UINavigationController視圖,實際上看起來像這樣在界面生成器:

enter image description here

但是當我運行的應用程序,該應用程序是這樣的:

enter image description here

爲什麼沒有加載的「ThirdView.xib」 UINavigationController的導航欄設計中的應用,因爲我已經把它設計界面生成器?

更新:這裏是「的firstView」怎麼看起來像在IB: enter image description here

回答

-1

每個UIViewController中的導航控制器負責提供內容要在導航欄上顯示。

在你的firstView的視圖didLoad方法執行以下操作

self.navigationItem.title = @"your title"; 

但你也張貼您如何看的firstView在IB?


我個人從未在IB中設置導航欄。 這裏如何可以在代碼中設置2鍵導航欄

self.navigationItem.leftBarButtonItem = self.editButtonItem; 

UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject)]; 
self.navigationItem.rightBarButtonItem = addButton; 
[addButton release]; 

此代碼來自一個UITableViewController子類。

+0

你有試過嗎?它在你的情況下工作嗎? –

+0

我知道如何以編程方式設置導航,我真的想知道如何才能看到我在界面生成器中製作的導航。你的xib中的 –

+0

在檢查器中設置視圖的xib。或以編程方式設置視圖,但不要推視圖控制器,它將控制導航欄上顯示的內容。 –

0

我不相信你想要做的是有效的。 UINavigationController旨在成爲其他視圖的容器。您可以創建UINavigationController,然後通過使用pushViewController將視圖控制器推送到其上來添加內容:animated :.它是使用.xib文件創建的推送視圖控制器。

+0

不知道你爲什麼被拒絕投票,你是完全正確的。他在做什麼不正確。您不能在XIB中使用自定義導航控制器 –