0

For some reason, when I try to open a view controller via modal segue, it opens up two of the same type. Why is this happening?

Warning: Attempt to present <ModalViewController: 0x7fa062c5edd0>  
on <HomeViewController: 0x7fa062e16e40> which is already presenting 
<ModalViewController: 0x7fa062fb9780>

This is causing problems because I try to use delegates, but my main view controller never gets the correct delegate.

The issue occurs when I click the the button which triggers showModalView

HomeViewController

- (IBAction)showModalView:(UIButton *)sender {
    ModalViewController *modalView = [[ModalViewController alloc] init];
    [self presentViewController:modalView animated:YES completion:nil];
}

I tried this solution here and here and a dozen other ones, but none seem to work for me.

Why is this happening?

Community
  • 1
  • 1
erad
  • 1,766
  • 2
  • 17
  • 26

1 Answers1

0

The problem you're having, is because you've connected a segue to the button, and are also presenting the controller in code; you should be doing one or the other. When you removed the segue, you got a black screen because you're using alloc init to create your controller. If you made the controller in a storyboard, then you should use instantiateViewControllerWithIdentifier: instead.

However, the easier way would be to leave the segue connected to the button, and delete the code you have in the button's action method. The button doesn't need an action method, if you have it hooked directly to a segue. All of this is covered in Apple's document, "View Controller Programming Guide for iOS". You should read it.

rdelmar
  • 103,982
  • 12
  • 207
  • 218