Reputation: 14123
Is it possible to hide UIBarButtonItem (rightButton of navigationBar) but not making it nil? In my application I have a condition
if(self.navigationItem.rightBarButtonItem == nil)
which is really important. But hiding the barButton is equally important.
Upvotes: 0
Views: 598
Reputation: 443
Please check my answer here to similar question. It's applicable here too.
It adds isHidden
property to UIBarButtonItem.
Upvotes: 0
Reputation: 13364
You can hide your button by which you have made your barbutton ....
UIButton *button1=[UIButton buttonWithType:UIButtonTypeCustom];
[button1 setFrame:CGRectMake(10.0, 2.0, 45.0, 40.0)];
[button1 addTarget:self action:@selector(showLeft:) forControlEvents:UIControlEventTouchUpInside];
[button1 setImage:[UIImage imageNamed:@"anyImage.png"] forState:UIControlStateNormal];
UIBarButtonItem *button = [[UIBarButtonItem alloc]initWithCustomView:button1];
self.navigationItem.leftBarButtonItem = button;
[button1 setHidden:YES];
Upvotes: 1
Reputation: 3364
One thing you can do is use the initWithCustomView
property of UIBarButtonItem
. Set up a UIButton
and use initWithCustomView
and assign it to this button. UIButton
has hiding and unhiding property.
UIButton*someButton=[UIButton UIButtonTypeRoundedRect];
UIBarButtonItem*someBarButton=[[UIBarButtonItem alloc] initWithCustomView:someButton];
//To Hide/Unhide
[someButton setHidden:YES/NO];
Upvotes: 2