iOS Prep for segue method

nashyo

macrumors 6502
Original poster
Oct 1, 2010
299
0
Bristol
Is this the correct way to write a prep for a segue method, if you have three buttons, each of which segue to different views.

Yes, the segues are named as you see them as string below.

Code:
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"AnswerA"])
    {
        ContentAViewController *cavc = [segue destinationViewController];
        cavc.currentContent = _currentContent;
    } else if ([segue.identifier isEqualToString:@"AnswerB"])
    {
        ContentBViewController *cbvc = [segue destinationViewController];
        cbvc.currentContent = _currentContent;
    } else if ([segue.identifier isEqualToString:@"AnswerC"])
    {
        ContentCViewController *ccvc = [segue destinationViewController];
        ccvc.currentContent = _currentContent;
    }
}
 

RonC

macrumors regular
Oct 18, 2007
108
0
Chicago-area
Looks about right, given the lack of context.

Are the buttons setup to be the segue source (not sure what the correct term is, but did you ctrl-drag from the button to the new view controller) or are they set to use IBActions where you have to write the code?
 

nashyo

macrumors 6502
Original poster
Oct 1, 2010
299
0
Bristol
I ctrl dragged from the buttons yes. Three buttons are each pushing to an individual view controller.

Doesn't work at runtime. If I remove if statements for answerB and answerC segues, at runtime the A button segues to answerA successfully and the others do not. If I run the code as you see it above, all segues fail.
 

nashyo

macrumors 6502
Original poster
Oct 1, 2010
299
0
Bristol
Fine now

I was blaming the wrong piece of code.

Turns out the load view method was not annotated as it originally was when the view controller was created for vcAnswerB and vcAnswerC - and the load view method was not calling [super load view];

Thanks for looking at this anyway.

Regards
Rob
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.