First let me explain the flow of my app,
When I launch the app I check if the user is logged in, I do this check in -(void) viewWillAppear:(BOOL)animated if not I show the login controller. Now this works perfectly.
In my loadView I access my Code Data stack and try and get the fetchedObjects to show in a table view, by clicking one of the cells I show more information on the clicked cell’s object.
This is how I do it.
AppDelegate *app = (AppDelegate*)[[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [app managedObjectContext];
NSFetchRequest* fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Sites" inManagedObjectContext:context];
NSError *error;
[fetchRequest setEntity:entity];
fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];
Now when the view loads the first time i get the following in the debugger
(lldb) po fetchedObjects
(NSArray *) $1 = 0x00352860 <_PFArray 0x352860>(
<NSManagedObject: 0x352550> (entity: Sites; id: 0x34c9b0 <x-coredata://7CD0A735-BC41-4E7A-8B07-C957E6096320/Sites/p1> ; data: <fault>)
)
Which appears to be fine.
Now viewWillAppear gets called and the login view gets shown and the user gets logged in and the login view is popped from the navigation stack, then the tableview’s cellforrowatindexpath gets called again, when I break there and I po my fetchedObjects again I get
(lldb) po fetchedObjects
(NSArray *) $3 = 0x00352860 [no Objective-C description available]
This I don’t understand, why does the data not get persisted?
The exception gets thrown in
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [fetchedObjects count];
}
fetchedObjects is a member of the class, I have no release for it yet and I never change its value?
Returns an autoreleased object. If you want it to hang around, you have to retain it or assign it via your
retained property accessor, if it exists (this is the preferred method):