每个选项卡中的一个导航栏实例

时间:2013-05-13 09:59:01

标签: ios objective-c uiviewcontroller uitabbarcontroller uinavigationbar

我这几天一直在努力解决这个问题。在我的应用程序中,我有内置UINavigationViewControllers的标签栏控制器。我希望每个导航控制器中的每个导航栏看起来完全相同,具体取决于用户操作和应用程序状态。 例如:如果用户在第一个视图控制器中登录我的应用程序,应用程序会在导航栏中设置其名称并将导航栏设置为登录状态。然后,当用户选择其他选项卡项时,我想将此登录状态的导航栏从第一个视图控制器设置为其他视图控制器。我试过使用单身但没有效果。

2 个答案:

答案 0 :(得分:0)

好像你必须做两件事:

  1. 在初始化UIViewController
  2. 时设置当前设置
  3. 状态更改后更新所有已启动的控制器
  4. 到1: 用

    创建一个类
    @interface UIViewController (UINavigationController)
    
    - (UINavigationController*)wrapWithNavigationController;
    
    @end
    
    @implementation UIViewController (UINavigationController)
    
    - (UINavigationController*)wrapWithNavigationController
    {
        UINavigationController* navigationController = [[UINavigationController alloc] initWithRootViewController:self];
    
        // your customizations
        navigationController.navigationBar.barStyle = UIBarStyleBlack;
        [...]
    
        return [navigationController autorelease];
    }
    
    @end
    

    您可以将其称为UIViewControllerAdditions

    到2:

    使用NSNotificationCenter进行更新:)

答案 1 :(得分:0)

您真的有多个UINavigationControllers,或者您只是想在每个标签中使用navigationBar获取相同的操作和功能?

如果您只想拥有该栏,您还可以使用UINavigationController作为应用rootViewController,然后使用UITabBarController作为childViewController UINavigationController }}