Search code examples
iosinheritanceuibuttonuinavigationitem

Remove navigation button


Hey, I've written a class (A) which inherits some functionality including an implementation of a navigation button. Class A has both a view and edit mode, I want to only show the button when am in edit mode. So far I've not been able to remove this button and I don't really want to create to another class just for edit.

Also other classes inherit this functionality so I don't really want to be messing about with parent.

The code that I use to create the button is below:

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];    
UIImage *buttonImage = [UIImage imageNamed:@"button.png"];

[button addTarget:self 
               action:@selector(buttonPressed:) 
     forControlEvents:UIControlEventTouchUpInside];

button.bounds = CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height);

[button setBackgroundImage:buttonImage forState:UIControlStateNormal];
[button setTitle:NSLocalizedString(@"BUTTON", @"") 
            forState:UIControlStateNormal];

LPRBSLabel *buttonLabel = [[LPRBSLabel alloc] initWithStyle:UICustomeButtonTitle];
[button setTitleEdgeInsets:UIEdgeInsetsMake(0.0, 0.0, -5.0, 0.0)];

button.titleLabel.font = buttonLabel.font;
[button setTitleColor:buttonLabel.textColor forState:UIControlStateNormal];
[buttonLabel release];

UIBarButtonItem *barLeftInfoButton = [[UIBarButtonItem alloc] initWithCustomView:button];
self.navigationItem.leftBarButtonItem = barLeftInfoButton;
[barLeftInfoButton release];

Solution

  • I managed to solve it using:

    self.navigationItem.leftBarButtonItem = nil;
    

    I had a mind freeze and was using the above statement before the button had actually when created :-(