0

I have a tableViewController and when a cell is clicked, I want to record the name of the cell and pass it to a new QuestionViewController programatically. The problem I'm getting is that when the cell is clicked, I get an error:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver () has no segue with identifier 'segueToViewController''

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    self.name = [self.listOfNames objectAtIndex:indexPath.row];
    NSLog(@"selected cell: %i, %@", (int)indexPath.row, self.listOfNames);
    [self performSegueWithIdentifier:@"segueToViewController" sender:self];
}


-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{

    NSLog(@"prepare for segue: %@", segue.identifier);
    if ([[segue identifier] isEqualToString:@"segueToViewController"]){

        QuestionViewController *QVC = segue.destinationViewController;
        QVC.currentResidentName = [[NSString alloc] initWithString:self.name];

}

}

Any idea how to make the segue work? I'm not sure why prepareForSegue is not able to identify the segue.

NSLog prints:

 selected cell: 0, 123456789

which is good, but it doesn't get to the "prepare for segue" NSLog. When I debug the problem, it crashes right at prepareForSegue

1 Answers1

0

Can you confirm that the segue exists in your storyboard? Even if triggered programatically the segue must exist in your storyboard as described here.

If the segue does exist, check for typos in its name. The name must be spelled the same way in your storyboard and in your code. (This has been a common source of bugs for me, and it seems there is no mechanism for ensuring that storyboard identifiers match the source code.)

If the segue exists and is spelled correctly, then this Stack Overflow thread points at other solutions for more exotic cases, such as projects with multiple storyboards. Also try doing a clean build as suggested in that thread.

Community
  • 1
  • 1
Greg Krimer
  • 121
  • 5