0

i use below cod to passing Data Back from second view controller to first view controller but it's not work, what is wrong?

- (IBAction)donePressed:(id)sender {

NSManagedObject *selectedGroup=[_group objectAtIndex:[[self.tableView indexPathForSelectedRow] row]];

ContactEditVC *firstViewController = [[ContactEditVC alloc] initWithNibName:@"ContactEditVC"  bundle:nil];
firstViewController .data=[NSString stringWithFormat:@"%@",[selectedGroup valueForKey:@"gName"]];
firstViewController ._group=selectedGroup;
[firstViewController .mybutton setTitle:@"success" forState:UIControlStateNormal];

  [self.navigationController popViewControllerAnimated:YES];
}

1 Answers1

0

You're creating a whole new view controller and setting that data instead of referencing the previous view controller.

The best approach to pass data back would be the delegate approach, seen here: https://stackoverflow.com/a/19343715/1066424

Alternatively, if you're dead set on setting the properties of the previous view controller directly, you can reference it like so by taking it from the navigation controller stack (but I very highly recommend not doing this):

UIViewControllers *viewControllers = [[self navigationController] viewControllers];
ContactEditVC *firstViewController = (ContactEditVC *)viewControllers[[viewControllers count] - 2];
// do stuff with the firstViewController here
Community
  • 1
  • 1
Aaron Wojnowski
  • 6,352
  • 5
  • 29
  • 46