I have tableViewController
class and want to pass a property to another view controller.
I declared my property,
@property (strong, nonatomic) NSIndexPath *selection;
In protocol tableView:didSelectRowAtIndexPath:
, I want to set my selection
value into indexPath
selected.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
// change your selection property
[self setSelection:indexPath];
}
I want to pass that selection
into destination view controller by prepareForSegue:sender:
if ([segue.identifier isEqualToString:@"updateItem"]) {
UINavigationController *navController = (UINavigationController *)[segue destinationViewController];
UpdateViewController *viewController = (UpdateViewController *)[navController topViewController];
[viewController setManagedObjectContext:self.managedObjectContext];
NSManagedObject *record = [self.fetchResultsController objectAtIndexPath:self.selection];
if (self.selection) {
[viewController setRecord:record];
}
// reset selection
[self setSelection:nil];
}
My problem is, I NSlog-ing that property on destination view controller and for the first time it showed as null. Secondly, it showed as it set for the first, and so on and so on. It showed what I set before.
So did I miss the concept of setting a property before it goes into another view controller destination? Please let me know this. Any help would be appreciated. Thank you so much.