0

我有一個包含的UITabBarController和一個UINavigationController(該的UITabBarController的標籤之一)類:在.m文件如何向UITabBarController中的UINavigationController添加一個右鍵?

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

} 

@property (retain, nonatomic) UIWindow *window; 

@property (retain, nonatomic) UITabBarController *tabBarController; 

@end 

(init方法),這是我如何努力,但它不工作:

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

我想把全國按鈕,我的UINavigationController的rightBarButtonItem *地圖,所以我插入上的init梅索德線(.m文件):

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

因爲我的類不是視圖(NSObject的子視圖)在viewDidLoad方法中插入該代碼。

+0

你是否綜合了你的屬性? – btype 2012-08-15 13:43:18

+0

我做了它插入(地圖的類)的viewDidLoad代碼,它的工作,我不刪除問題,因爲它可能有一天可以幫助某人。 – zakari 2012-08-15 13:44:13

+0

如果您找到了解決方案,請在解釋它的問題中添加一個答案。 – 2012-08-15 14:32:26

回答

0

地圖本身不是一個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; 
相關問題