2013-03-06 80 views
3

我正在用模態塞格展示UIViewController。 這UIViewController中繼承了一個UINavigationBar的,我已經設置的UIBarButtonItem左側導航欄:隱藏或禁用UINavigationBar中的UIBarButtonItem

HELP ME!!!

我的問題是,當呈現的UIViewController的viewWillAppear中調用方法,我想隱藏UIBarButtonItem,但總是出現UIBarButtonItem。 我已經爲UIViewController聲明瞭一個名爲myCancelButton的UIBarButtonItem,並且我在Interface Builder中引用了它。

這是我到目前爲止已經試過(全部不工作):

- (void) viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 

    self.navigationItem.leftBarButtonItem = nil; 
    self.navigationItem.backBarButtonItem = nil; 
    self.myCancelButton = nil; 

    NSMutableArray *barButtonItems = [self.navigationItem.leftBarButtonItems mutableCopy]; 
    [barButtonItems removeObject:self.myCancelButton]; 
    self.navigationItem.leftBarButtonItems = barButtonItems; 

    [self.navigationItem.leftBarButtonItems delete:self.myCancelButton]; 

    self.navigationController.navigationItem.leftBarButtonItem = nil; 
    barButtonItems = [self.navigationController.navigationItem.leftBarButtonItems mutableCopy]; 
    [barButtonItems removeObject:self.myCancelButton]; 
    self.navigationController.navigationItem.leftBarButtonItems = barButtonItems; 

    [self.navigationController.navigationItem.leftBarButtonItems delete:self.myCancelButton]; 

    [self.myCancelButton setWidth:0.01]; 

    self.navigationItem.hidesBackButton = TRUE; 

    //Even setting enabled to false doesn't work: 
    [self.myCancelButton setEnabled:FALSE]; 
} 

回答

1

這應該工作。

[self.navigationItem setHidesBackButton:YES animated:YES]; 
+0

,這是行不通的。 我已經跑出了想法。 – w3bshark 2013-03-06 12:57:11

0

嘗試不幸的是使用一個

self.navigationController.navigationItem.leftBarButtonItem = nil; 
[self.navigationController.navigationItem setHidesBackButton:YES]; 
+0

我已經在我原來的帖子中試過這些: self.navigationController.navigationItem.leftBarButtonItem = nil; self.navigationItem.hidesBackButton = TRUE; – w3bshark 2013-03-06 12:59:40

+0

只是等我很忙。如果我會自由閱讀,那麼我會閱讀這篇文章。 – 2013-03-06 13:03:43

+0

您有沒有機會找到解決方案? – w3bshark 2013-03-08 15:04:07