2012-09-07 42 views
0

我有兩個ViewController從第一個我添加了兩個欄按鈕到第二個ViewController。代碼這裏 - `從另一個ViewController隱藏欄按鈕(左右兩側)?

self.navigationItem.leftBarButtonItem = 
[[[UIBarButtonItem alloc] 
    initWithBarButtonSystemItem:UIBarButtonSystemItemCancel 
    target:self 
    action:@selector(backBtnAction)] autorelease]; 
self.navigationItem.rightBarButtonItem = 
[[[UIBarButtonItem alloc] 
    initWithBarButtonSystemItem:UIBarButtonSystemItemDone 
    target:callListViewCtrObj 
    action:@selector(saveListNameAction)] autorelease]; 
self.navigationItem.rightBarButtonItem.tintColor = [UIColor blueColor];` 

現在我想刪除這兩個按鈕時,完成按鈕點擊(即callListViewCtrObj的saveListNameAction被調用時,看到上面的代碼),我已經試過像這 - homeViewCtrObj.navigationItem.leftBarButtonItem = nil; homeViewCtrObj.navigationItem.rightBarButtonItem =nil; 其中homeViewCtrObj爲對象第一視圖控制器。

任何建議或示例代碼將不勝感激。 謝謝。

回答

2

在CallListViewCtr爲HomeViewCtr

@property (nonatomic, assign) HomeViewCtr *homeView; 

創建屬性現在,當你把這個觀點可以確保到新創建的viewController分配給該屬性。現在

self.homeView = theNewViewControllerImAboutToPush; 

可以使用

self.homeView.navigatioItem.leftBarButtonItem = nil; 
self.homeView.navigatioItem.rightBarButtonItem = nil; 

我想你會想homeView設爲零,當你完成。

+0

另一種選擇是在初始化即將推入的視圖後,您可以將按鈕設置爲零。 – Hackmodford

+0

在這種情況下,你不會使用自己 – Hackmodford

+0

謝謝..工作! – Bharat

2

嘗試

self.navigationItem.leftBarButtonItem = nil; 
self.navigationItem.rightBarButtonItem = nil; 
+0

感謝您的快速回復,但它不起作用。 – Bharat

+0

爲我工作... – Hackmodford

+0

@Hackmodford在我的情況我試圖隱藏從HomeViewCtr,從不同的ViewController(CallListViewCtr)中放置的酒吧按鈕,那麼我怎麼能指向從CallListViewCtr HomeViewCtr的按鈕,使用self.something (自己指示當前對象?) – Bharat

相關問題