如何在UITabBarController中向UINavigationController添加右键?

时间:2012-08-15 13:29:58

标签: iphone ios uinavigationcontroller uitabbarcontroller uinavigationbar

我有一个包含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的子)。

1 个答案:

答案 0 :(得分:0)

Maps本身不是viewController,而是一个管理视图的容器对象。在某些时候,地图有一个或多个viewControllers - 它应该总是有一个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;