0
votes

A few hours ago this code gave me no problems, however, after updating my XCode my XCode and removing a 3rd party framework, it is suddenly giving me the above exception. I'm extremely confused because I don't think anything's changed between then and now that could cause the problem besides updating my XCode. Can anyone see an issue?

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

/*We check to make sure the segue corresponds to segue we created when a cell is selected*/
if ([[segue identifier] isEqualToString:@"show"]) {

   /*Get a pointer to the selected row*/
    NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];

    /*Get a pointer to the ViewController we will segue to*/
    ViewController *viewController = segue.destinationViewController;

    /*Pass the dialect and code back to the ViewController*/
   viewController.language = self.languages.allKeys[indexPath.row];
    viewController.code = [self.languages objectForKey:viewController.language];

  }
}

Specifically, the following two lines are causing the exception:

viewController.language = self.languages.allKeys[indexPath.row];
viewController.code = [self.languages objectForKey:viewController.language];
1

1 Answers

4
votes

Your segue's destination controller is a UINavigationController, your view controller is likely the top view controller of that navigation controller. You probably want:

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

    /*We check to make sure the segue corresponds to segue we created when a cell is selected*/
    if ([[segue identifier] isEqualToString:@"show"]) {

    /*Get a pointer to the selected row*/
    NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];

    UINavigationController *navController = segue.destinationViewController

    /*Get a pointer to the ViewController we will segue to*/
    ViewController *viewController = navController.topViewController;

    /*Pass the dialect and code back to the ViewController*/
    viewController.language = self.languages.allKeys[indexPath.row];
    viewController.code = [self.languages objectForKey:viewController.language];
  }
}