2012-05-25 24 views
0

我的主菜單(一個ViewController)嵌入在Xcode4的故事板中添加的NavigationController中。 我的菜單中有一個按鈕,顯示一個新的視圖。要顯示它我使用:我在IBAction調用的視圖中沒有導航欄?

- (IBAction) display : (id) sender 
{ 
    if(!anotherView) anotherView = [[AnotherView alloc] initWithNibName:@"AnotherView" bundle:nil]; 
    [self presentModalViewController:anotherView animated:NO]; 
} 

我的其他視圖正確顯示其所有對象和元素。不包括我的NavigationController的欄,這沒有出現。爲什麼?

感謝您的建議

回答

1

您呈現視圖modally你大概的意思是

[self.navigationController pushViewController:anotherView animated:YES] 
當然

你真正想做的是不能混合和匹配故事板和非故事板流量,不必要的像這樣,並擁有sto ryboard爲你做這個

+0

非常感謝這個建議。 – Rob

1

你是模態展示您的viewController。如果您想使用導航控制器,則必須將視圖推送至導航堆棧。

更換

[self presentModalViewController:anotherView animated:NO]; 

[self.navigationController pushViewController:anotherViewController animated:YES]; 
+0

非常感謝! – Rob

0

你仍然可以呈現你的視圖模式,而不會丟失導航欄。試試這個代碼:

AnotherView *tempAnotherView = [[AnotherView alloc] initWithNibName:@"AnotherView" bundle:nil]; 
[self setAnotherView:tempAnotherView]; 
[tempAnotherView release]; 

UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:self.anotherView] autorelease]; 
[self.navigationController presentModalViewController:navController animated:YES]; 

希望它能幫助! :)