【问题标题】:Different UITabbar buttons不同的UITabbar按钮
【发布时间】:2011-12-23 12:45:19
【问题描述】:

我的问题是关于 UITabbar 控制器的。 我有一个 UInavigation 控制器和一个 UITabbarcontroller 都在我的 Appdelegate 中声明。但是当我的 UIViewController 被 NavigationController 更改时,我希望我的标签栏按钮发生变化。

 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;

如何做到这一点?

【问题讨论】:

    标签: objective-c ios uitabbarcontroller


    【解决方案1】:

    使用 UINavigationControllerDelegate

    @interface SettingsViewController : UIViewController <UINavigationControllerDelegate> 
    

    在.h文件中

    然后

    .m 文件中的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 中,但两个按钮仍然在我的屏幕上,在我的应用程序的任何地方,相同的 tabbarItems 在 TabbarController 上。
    • @user1113419 不工作什么?当您显示新控制器时,navigationController didShowViewController 方法确实调用了。如果你在这些时候需要做某事,你需要在这个方法中自己动手。
    • 这两种方法自己什么都不做。但是您可以在其中更改标签栏按钮,例如 viewController.tabBarItem.image = [UIImage imageNamed:@"some_icon.png"];
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-20
    • 2019-01-31
    相关资源
    最近更新 更多