【问题标题】:How to add a right button to a UINavigationController in a UITabBarController?如何在 UITabBarController 中向 UINavigationController 添加右键?
【发布时间】:2012-08-15 13:29:57
【问题描述】:

我有一个包含 UITabBarController 和 UINavigationController(UITabBarController 的选项卡之一)的类:

 @interface HomeController : NSObject{
UINavigationController *maps;
UIBarButtonItem* national;

}

@property (retain, nonatomic) UIWindow *window;

@property (retain, nonatomic) UITabBarController *tabBarController;

@end

在 .m 文件(init 方法)中,这是我正在尝试的方式,但它不起作用:

self.tabBarController.viewControllers = [NSArray arrayWithObjects:adminController, maps, sitesController, nil];

我想将国家按钮作为我的 UINavigationController *maps 的 rightBarButtonItem,所以我在 init 方法(.m 文件)中插入了这些行:

 national= [[UIBarButtonItem alloc] initWithTitle:@"national" style:UIBarButtonItemStyleDone target:nil action:nil];
    maps.navigationItem.rightBarButtonItem = national;
    [national release];

因为我的类不是在 viewDidLoad 方法中插入代码的视图(NSObject 的子类)。

【问题讨论】:

  • 你的属性合成了吗?
  • 我在(地图类)的 viewDidLoad 中插入了该代码,它起作用了,我没有删除问题,因为它可能有一天会帮助某人。
  • 如果您找到了解决方案,请为您的问题添加一个解释它的答案。

标签: iphone ios uinavigationcontroller uitabbarcontroller uinavigationbar


【解决方案1】:

Maps 本身并不是一个 viewController,而是一个管理视图的容器对象。在某些时候,地图有一个或多个 viewController——它应该总是有一个 rootViewController。所以试试这个:

...create and initialize maps
UIViewController *firstView = maps.rootViewController;
firstView.view; // force it to load its view, may or may not be necessary
firstView.navigationItem.rightBarButtonItem = national;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-25
    • 1970-01-01
    • 1970-01-01
    • 2011-08-20
    • 1970-01-01
    相关资源
    最近更新 更多