I have a UITableViewController that displays cells that are just default. Each cell can be touched and taken to a list that is within the “account” that each cell in the first view holds.
I connected everything up with a segue and then in my first view I call:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
Account *nextAccount = [self.list objectAtIndex:indexPath.row];
DetailViewController *viewController = (DetailViewController *)[segue destinationViewController];
viewController.account = nextAccount;
}
}
and then in the detail view’s viewDidAppear:(BOOL)animated I say:
- (void)viewDidAppear:(BOOL)animated {
self.list = [self.account.list mutableCopy];
}
and then I have a UITableViewController on the detail view but in the cellForRowAtIndexPath: method I access the self.list but it doesn’t seem to be working. I know my cellForRowAtIndexPath: works because earlier I did some template work with the method and it worked fine. It seems to be just the prepareForSegue: isn’t working or the property isn’t being set.
Thanks in advance!
It’s probably trying to set up the detail table view long before viewDidAppear is called. Instead try overriding the setter for the data model:
Then it should create the copy before the view is loaded.
Also if you’re going to override viewDidAppear, be sure to call the super: