Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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];
like image 400
wibosco Avatar asked Feb 28 '11 10:02

wibosco


2 Answers

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 :-(

like image 62
wibosco Avatar answered Sep 22 '22 16:09

wibosco


It would be easier to set the NavigationItem's property "hidesBackButton" to yes:

http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UINavigationItem_Class/Reference/UINavigationItem.html#//apple_ref/occ/cl/UINavigationItem

like image 32
NovaJoe Avatar answered Sep 21 '22 16:09

NovaJoe