1
votes

I'm using a storyboard with a navigation controller and two simple table views to make a very basic app in an iOS tutorial.

I've connected the initial view to my second view with a Show segue and given it the identifier "S1". In the view controller for my initial view I have this code:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    // Perform Segue
    [self performSegueWithIdentifier:@"S1" sender:self];
}

In the view controller for my second view I have the following code:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    NSLog(@"Triggered Segue");
}

However, when I select a row in the first view, the NSLog call never happens. The second view opens, but it's completely blank.

I'm sure I'm missing something very basic here, but I'm stumped. I've set a debug point in didSelectRowAtIndexPath and I can confirm that it's being called. When I try to step into performSegueWithIdentifier nothing happens. Breakpoints in prepareForSegue in my second view don't trigger but ones in viewDidLoad do. Any help for a new iOS dev?

1
the prepare for segue should be in the first view controller i thinkchris
yes move the prepareForSegue to the same view controller that has performSegueWithIdentifieruser3435374

1 Answers

3
votes

performSegueWithIdentifier manually triggers the Segue. You get an opportunity to set variables etc. in prepareForSegue. Both methods need to be in the same ViewController.