我的选项卡栏有10个选项卡。其中六个因此被推入“更多”标签。其中有几个没有UINavigationControllers。即,该选项卡由不是导航控制器的UIViewController子类控制。iPhone - 在用户选择moreNavigationController中的选项卡时添加一个导航栏按钮
当用户选择其中的一个时,相应的视图控制器会出现,顶部有一个UINavigationBar。
我想为该导航栏添加一个按钮。我怎样才能做到这一点?
谢谢。
我的选项卡栏有10个选项卡。其中六个因此被推入“更多”标签。其中有几个没有UINavigationControllers。即,该选项卡由不是导航控制器的UIViewController子类控制。iPhone - 在用户选择moreNavigationController中的选项卡时添加一个导航栏按钮
当用户选择其中的一个时,相应的视图控制器会出现,顶部有一个UINavigationBar。
我想为该导航栏添加一个按钮。我怎样才能做到这一点?
谢谢。
好吧,如果你想以编程方式做到这一点,那么我建议那所房子的各个视图控制器UINavigationControllers替换你的UITabBar每个viewControllers的。
所以,你的旧代码看起来是这样的:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
UITabBarController *tbc = [[[UITabBarController alloc]init]autorelease];
[window addSubview:tbc.view];
UIViewController *mapVC = [[[UIViewController alloc] init]autorelease];
NSArray *tabViewControllerArray = [NSArray arrayWithObjects:self.mapVC, nil];
tbc.viewControllers = tabViewControllerArray;
}
新的代码应该是:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
UITabBarController *tbc = [[[UITabBarController alloc]init]autorelease];
[window addSubview:tbc.view];
UIViewController *mapVC = [[[UIViewController alloc] init]autorelease];
// add the viewController to a UINavigationController
UINavigationController *mapNav = [[[UINavigationController alloc] initWithRootViewController:mapVC]autorelease];
// put the nav controller in the array instead
NSArray *tabViewControllerArray = [NSArray arrayWithObjects:mapNav, nil];
tbc.viewControllers = tabViewControllerArray;
// this code adds a right button to the mapBav navigationBar
// this uses a custom view, but you could use a standard UIBarButtonItem too
NSArray *items = [NSArray arrayWithObjects: [UIImage imageNamed:@"flag-icon.png"], nil];
UISegmentedControl *tableControl = [[[UISegmentedControl alloc] initWithItems:items]autorelease];
tableControl.segmentedControlStyle = UISegmentedControlStyleBar;
UIBarButtonItem *segmentBarItem = [[[UIBarButtonItem alloc] initWithCustomView:tableControl] autorelease];
self.navigationItem.rightBarButtonItem = segmentBarItem;
}
有两种方法可以解决这个问题。
只需使用一个UINavigationController为每个选项卡,与您的视图控制器在其中。但它听起来像你不想这样做,所以:
把UINavigationBar放入使用Interface Builder。 nav bar http://cl.ly/395fb8c0a9e9df781897/content
然后,您可以在UIBarButtonItems中拖动并根据自己的喜好对其进行配置,同样也可以在IB中进行配置。 buttons http://cl.ly/7501d3e8e5d57dac5e00/content