Reputation: 1928
I have a weird problem related to passing an instance of a NSManagedObject to another viewcontroller.
I pass an instance of NSManagedObject fetched from a NSFetchResultsController like so: to another viewcontroller.
- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
Product* product = (Product*)[self.fetchedResultsController objectAtIndexPath:indexPath];
DetailViewController* pDetailVC = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailViewController"];
pDetailVC.product = product;
pDetailVC.managedObjectContext = self.managedObjectContext;
[self.navigationController pushViewController:pDetailVC
animated:YES];
}
I am using Restkit and my managedObjectContext is the RKManagedObjectStore mainQueueManagedObjectContext.
My application does also consists of an UITabbarController.
I then access the passed objects properties in the cellForAtIndexPath in the viewcontroller which the object is passed to, like so:
cell.descLabel.text = self.product.info;
In my viewDidAppear method of this viewcontroller I reload the tableView, to show the data of the passed instance. This works fine the first time, when the object is passed to the viewcontroller, but if I then switch to another viewcontroller using the tabbar and then return to the viewcontroller, all the data of the passed object is null, it has been turned into a fault.
How can I prevent this for happening, prevent that the data is null/faulted when I come back to the viewcontroller?
Upvotes: 2
Views: 153
Reputation: 1218
The viewDidAppear
is called each time you switch to that tabBar, not sure of why is causing a fault on your NSManagedObject
, that would depend if your are making other changes on the same context.
If you are using this NSmanagedObject
just to display its properties, I recommend you pass your NSmanagedObject
info to a custom NSObject
subclass and use that object on your table data source
Upvotes: 1