It looks like you're using didSelectRowAtIndexPath
and a segue. You should use one or the other. So, you could either:
You could retire your
didSelectRowAtIndexPath
method and then have aprepareForSegue
that:- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([segue.identifier isEqualToString:@"CellSelection"]) { CellSelectionViewController *controller = (CellSelectionViewController *)segue.destinationViewController; controller.msg = [_types objectAtIndex:[self.tableView indexPathForSelectedRow].row]; } }
Alternatively, you could remove the segue from the table view cell to the next scene, but rather define it to be between the two view controllers, give it an identifier, and then have
didSelectRowAtIndexPath
invoke it after your property was set:- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { _type = [_types objectAtIndex:indexPath.row]; [self performSegueWithIdentifier:@"yoursegueidhere" sender:@"self]; }
But don't have both a segue from the cell and a didSelectRowAtIndexPath
method. You have no assurances as to the order they will be performed. I'd be inclined to adopt the first approach and retire didSelectRowAtIndexPath
altogether.