我已经为这个问题苦苦挣扎了好几天。在我的应用程序中,我有标签栏控制器,里面有 UINavigationViewControllers。我希望每个导航控制器中的每个导航栏都根据用户操作和应用程序状态看起来完全相同。例如:如果用户在第一个视图控制器中登录我的应用程序,应用程序在导航栏中设置他的名字并将导航栏设置为登录状态。然后,当用户选择其他选项卡项时,我想将导航栏的登录状态从第一个视图控制器设置为其他视图控制器。我试过使用单例但没有效果。
问问题
238 次
2 回答
0
您真的有多个UINavigationControllers
,还是只想navigationBar
在每个选项卡中使用相同的操作和功能?
如果您只想拥有 bar,您也可以使用 anUINavigationController
作为您的应用程序rootViewController
,然后使用UITabBarController
as a childViewController
of your UINavigationController
.
于 2013-05-13T10:53:52.473 回答
0
似乎你必须做两件事:
- 在初始化时设置当前设置
UIViewController
- 状态更改后更新所有启动的控制器
to 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进行更新 :)
于 2013-05-13T10:11:31.187 回答