2012-01-12 96 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

相关问题