Prep for segue method

Discussion in 'iOS Programming' started by nashyo, Jan 12, 2012.

  1. nashyo macrumors 6502

    nashyo

    Joined:
    Oct 1, 2010
    Location:
    Bristol
    #1
    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;
        }
    }
     
  2. RonC macrumors regular

    Joined:
    Oct 18, 2007
    Location:
    Chicago-area
    #2
    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?
     
  3. nashyo thread starter macrumors 6502

    nashyo

    Joined:
    Oct 1, 2010
    Location:
    Bristol
    #3
    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.
     
  4. nashyo thread starter macrumors 6502

    nashyo

    Joined:
    Oct 1, 2010
    Location:
    Bristol
    #4
    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
     

Share This Page