I am presenting a UIViewController with a Modal Segue. This UIViewController inherits a UINavigationBar and I have set a UIBarButtonItem on the left side of the Navigation Bar:

My problem is that when the viewWillAppear method of the presented UIViewController is called, I'm trying to hide the UIBarButtonItem, but the UIBarButtonItem always appears. I've declared a UIBarButtonItem for the UIViewController, named myCancelButton, and I've referenced it in Interface Builder.
Here's what I've tried so far (all of which does not work):
- (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];
}
This should work.
[self.navigationItem setHidesBackButton:YES animated:YES];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With