2010-06-02 184 views
1

我在將按鈕添加到導航欄時出現問題。我的應用程序由兩個視圖控制器添加到tabBarController的viewControllers數組中。 Inturn這個tabBarController被添加到navigationController的viewControllers數組中。在其中一個視圖中,我有一個用於輸入日期的文本框。點擊這個文本框時,日期選擇器將彈出。同時我想在導航欄上顯示完成按鈕。我怎麼能做到這一點...我嘗試使用將按鈕添加到導航欄

self.tabBarController.navigationController.navigationItem.rightBarButtonItem = self.doneButton; 

但是,這是不工作...

請幫助我..

+0

我有同樣的問題。我們可以通過Interface Builder來做到嗎? – 2011-06-13 03:09:28

回答

1

與此

UIBarButtonItem* _doneButton; 
self.navigationItem.rightBarButtonItem = _doneButton; 
+0

espuz ...我試過這個......但是..不工作... thanx爲你的答覆...任何其他解決方案? – user347161 2010-06-02 11:42:16

2

嘗試試試這個代碼,

UIBarButtonItem *addButton = [[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Done", @"") 
                   style:UIBarButtonItemStyleBordered 
                   target:self 
                   action:@selector(DoneButton)] autorelease]; 

self.navigationItem.rightBarButtonItem = addButton; 

Best的運氣。

+0

謝謝你的回覆可以....我試過這個,但這是行不通的..有沒有其他方式....? – user347161 2010-06-02 11:40:55

+0

@刪除。這只是顯示按鈕。你可以在「 - (void)DoneButton {}; – Pugal 2010-06-02 11:45:23

+0

ya ...中編寫任何動作,但按鈕本身沒有顯示...! – user347161 2010-06-02 11:48:08

0

使用這一個:

UIButton *myBtn = [[UIButton alloc]init]; 
[self.navigationItem.titleView addSubview:myBtn];