不同的UITabbar按钮
问题描述:
我的问题是关于UITabbarcontroller。 我有一个UInavigation控制器和一个UITabbarcontroller都在我的Appdelegate中声明。但是,我希望我的标签栏按钮更改当我的UIViewController由NavigationController更改。不同的UITabbar按钮
SettingsViewController *sett = [[SettingsViewController alloc]init];
self.navigationController = [[UINavigationController alloc]init];
[self.navigationController.navigationBar setTranslucent:NO];
[self.navigationController.navigationBar setTintColor:[UIColor blackColor]];
self.navigationController.viewControllers = [NSArray arrayWithObject:viewController1];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:self.navigationController,sett, nil];
self.window.rootViewController = self.tabBarController;
如何做到这一点?
答
使用UINavigationControllerDelegate
@interface SettingsViewController : UIViewController <UINavigationControllerDelegate>
在.m文件.h文件中
然后
self.navigationController.delegate = self;
你检测NavigationController与方法改变
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
仍然没有工作,做了你所说的并将这些委托方法放置在SettingsViewController中,但这两个按钮仍然在我的屏幕上,在我的应用程序中的任何地方,TabbarController上都有相同的tabbarItems。 – SjorsJK 2011-12-23 13:19:02
@ user1113419不工作是什么?当您显示新的控制器时,navigationController didShowViewController方法确实会调用。如果您在这段时间需要做些什么,您需要亲自操作这种方法。 – Padavan 2011-12-23 13:21:19
请参阅编辑! – SjorsJK 2011-12-23 14:16:53