0

I view controller that has different buttons a user can interact with. Each one does something different, but they all present a new view controller modally. The problem is that a user has time to tap another button before the first presentation has happened, which results in a crash. Is there a way to prevent a user from tapping another button or detect if a modal presentation is already going to happen?

I just don't want to let users present more than 1 modal view controller at a time.

BlueBear
  • 7,469
  • 6
  • 32
  • 47
  • 1
    You can show the modal view controller without animations. Or disable other buttons while another view controller is showing. Will that work? – uiroshan May 06 '14 at 02:02
  • I definitely need to have the presentation be animated. Also it might be possible to disable the buttons, but some of them don't need to be. Do you think I should just manually disable the buttons I don't want touched upon the possibility of presentation? – BlueBear May 06 '14 at 02:09
  • When you click the button to present set all the button to enable NO. Then after present the NewViewController from the class call the delegate to enable all the button to YES in master viewcontroller. – TamilKing May 06 '14 at 04:14

2 Answers2

0
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{

if ([[segue identifier] isEqualToString:@"whateverSegue"])
    {
    [button setEnabled:NO];
    }
}

This should do the trick if its just once - otherwise a helper method called disableButtons or something to call if its in a few places should do the trick!

caleb
  • 11
  • 3
0

Check whether following steps are helpful.

Once you clicked button, you can disable the user interactions of the view.

-(IBAction)clickedButton:(id)sender {
   [self.view setUserInteractionEnabled:NO];

   // Do other things here
}

When model view controller appeared enable the user interactions of the view.

[self presentViewController:aViewController animated:YES completion:^{
   [self.view setUserInteractionEnabled:NO];
}];

Alternatively you can try following methods to disable touches in your Application

[[UIApplication sharedApplication] beginIgnoringInteractionEvents];

[[UIApplication sharedApplication] endIgnoringInteractionEvents];

https://stackoverflow.com/a/16609327/1208276

Community
  • 1
  • 1
uiroshan
  • 5,021
  • 2
  • 39
  • 37