2012-01-12 42 views
0

你好朋友我在NavigationbarrootViewController上加了UIImageViewUIBarButtonItem。點擊BarButten它推送第二個viewController。直到這一切都可以正常工作,但是當我彈出次級viewController UIBarButtonrootViewController得到不可見。任何人都可以告訴我如何解決這個問題。保持rightbarButton的可見性?

nav = [[UINavigationController alloc] init]; 
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, nav.navigationBar.frame.size.width, nav.navigationBar.frame.size.height)]; 
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
{ 
    UIImage *navImage = [UIImage imageNamed:@"NavBar-iPad.png"]; 
    imageView.image = navImage; 
} 
else 
{ 
    UIImage *navImage = [UIImage imageNamed:@"NavBar-iPhone.png"]; 
    imageView.image = navImage; 
} 

[nav.navigationBar addSubview:imageView]; 
[imageView release]; 

[nav pushViewController:viewController animated:YES]; 
+0

號沒有人,但你可以解決這個問題。但是,如果您發佈了相關的代碼片段,那麼這裏可能有人可以幫助您。 – PengOne 2012-01-12 06:03:21

+1

把你的代碼放在viewWillAppear中rootViewController – Hiren 2012-01-12 06:05:52

+0

我已經把我的代碼@PenOne – 2012-01-12 06:29:18

回答

0

它消失的原因是每個UIViewController都有自己的一組按鈕/標題顯示在導航欄上。所以當你推新視圖時,它會自動隱藏下面的按鈕/標題。

如果你想看看相同的按鈕,你必須在新的UIViewController中重新創建它們。

如果您需要的那些按鈕,而不是推一個新的視圖控制器,就像你現在,你 可以這樣做:

UINavigationController * navcontrol = [[UINavigationController alloc] initWithRootViewController: viewcontroller]; 
[navcontrol setNavigationBarHidden: YES]; 
[self.navigationController pushViewController: navcontrol animated:YES]; 
[navcontrol release]; 
[viewcontroller release]; 
+0

我覺得有一個混淆。我不想在新的viewController中的按鈕。我希望當我從第二個ViewController返回到rootViewController時,BarButton應該像在推送第二個ViewController之前一樣可見。感謝您的迴應。 – 2012-01-12 11:41:19

+0

你可以在你創建barbutton的地方發佈你的代碼嗎? – 2012-01-14 05:01:41