Segue not calling prepareForSegue
Asked Answered
A

4

9

Perhaps I am missing something simple. I added a modal segue from a button to a view controller. I then added some steps to prepareForSegue (and checked I had named the segue correctly). I have done this a few other times with no problem.

Now, when I click the button, the modal window opens, but the prepareForSegue does not fire. I tried putting a log statement in the prepareForSegue before it even checks the description of the label (so theoretically it should fire for any segue). But I get nothing logged.

Any ideas?

Allain answered 22/1, 2012 at 6:11 Comment(0)
A
9

Well I found the rookie error I suspected. I duplicated a VC and forgot to set it's class to my new VC class.

Allain answered 22/1, 2012 at 15:46 Comment(1)
I'm filing like noob [)Jampack
C
13

Connecting a segue from a button to the next controller is the correct way to connect it, just remember that prepareForSegue: is called on the VC that owns the button not the incoming controller. You get the incoming controller by calling [segue destinationViewController].

Conchiolin answered 22/1, 2012 at 14:16 Comment(1)
Thanks - but I've checked and I am calling prepareForSegue in the VC that owns the button.Allain
A
9

Well I found the rookie error I suspected. I duplicated a VC and forgot to set it's class to my new VC class.

Allain answered 22/1, 2012 at 15:46 Comment(1)
I'm filing like noob [)Jampack
R
0

Wire up the Segue to the VC not the button. Then in the touchUpInside event, put

[self performSegueWithIdentifier:@"segueid" sender:nil];

I almost always wire the segue up to either the VC or a tableviewcell (if I am using a static cell TV)

Rajewski answered 22/1, 2012 at 13:59 Comment(2)
I'm sure this would work, but the point of segues is to do this for me, no? In all of my other segues it has not been necessary to do this.Allain
You are correct, it should work the way you have it. I just like to have a little more control. Check that you do indeed have the button wired up (delete the segue and add it back in making sure you have the button selected in the storyboard view before control dragging to the other VC.Rajewski
R
0

You should set cell's reuse identifier set before segue is called. I tried lots of solutions like above and checked VC settings but didn't set the prototype cell's reuse identifier.

Only after I set this to "Cell" , it worked finally.

Reach answered 14/6, 2016 at 3:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.