Reputation: 1699
i create a right bar buttton item programatically. Andi place one UIVIEW in my view controller. And i have adde the action for my bar button item
. But now what i have did is, first time my UIVIEW will be hidden. And when my bar button item press my UIVIEW should be show.
What i need is , when same button click my same UIVIEW should hide and show.Here is my code;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_barButton.target = self.revealViewController;
_barButton.action = @selector(revealToggle:);
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
UIBarButtonItem *chkmanuaaly = [[UIBarButtonItem alloc]initWithTitle:@"Demo "style:UIBarButtonItemStylePlain target:self action:@selector(nextview)];
self.navigationItem.rightBarButtonItem=chkmanuaaly;
RightMenu.hidden = YES;
}
-(void)nextview{
NSLog(@"Right button pressed");
RightMenu.hidden = NO;
}
How can i hide again i press my same right bar button item
.
Please help me out.Thanks
Upvotes: 0
Views: 47
Reputation: 588
I have checked this code.This will work:
@implementation viewcontroller
bool isShown = false;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_barButton.target = self.revealViewController;
_barButton.action = @selector(revealToggle:);
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
UIBarButtonItem *chkmanuaaly = [[UIBarButtonItem alloc]initWithTitle:@"Demo "style:UIBarButtonItemStylePlain target:self action:@selector(nextview)];
self.navigationItem.rightBarButtonItem=chkmanuaaly;
RightMenu.hidden = YES;
}
-(void)nextview{
NSLog(@"Right button pressed");
if (!isShown) {
RightMenu.hidden = NO;
isShown = true;
} else {
RightMenu.hidden = YES;
isShown = false;
}
}
Let me know, if it's work.
Upvotes: 2