I’m having an issue when someone taps the rightBarButtonItem on the navigation bar and taps it again quickly that the program crashes. It’s understandable that is crashes because the new view hasn’t finished loading yet and the button is still visible to tap again so it will attempt to push the view again crashing the program. I’ve tried a couple of methods to try and prevent this and my current implementation somewhat works, but I know there is a better solution, perhaps a solution built into the framwork?
- (void) loadView
{
[super loadView];
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]
initWithTitle:@"Members"
style:UIBarButtonItemStylePlain
target:self
action:@selector(showRoster)] autorelease];
}
-(void) showRoster {
if (seconds + 3 < [[NSDate date] timeIntervalSince1970]) { //This is where I am trying to prevent the button from being activated twice.
seconds = [[NSDate date] timeIntervalSince1970];
vcRoster = [[RosterDataViewController alloc] init];
vcRoster.rosterDataModel.group_id = self.tweetsByGroupIdModel.group_id;
[self.navigationController pushViewController:vcRoster animated:YES];
}
}
I’ve also tried this, but it’s not doing what I am thinking it should be doing.
if (!self.navigationController.isBeingPresented)
I’ve tried solving the problem and Googling my way to an answer, but I have yet to find a good solution to this problem. I know the above is not a good way to do things, I’m open to suggestions for any improvements at all as I am extremely new to the IOS world. Thanks in advance for any help.
Try disabling the button as soon as the action method is run:
You can enable it later, to make it responsive again. How you can best do that depends on the view you are showing: if it is full screen, you might simply re-enable the button in
viewDidAppear:(i.e., after the view has disappeared and your button is visible again).