3
votes

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:

HELP ME!!!

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];
}
2

2 Answers

1
votes

This should work.

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

Try to use this one

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