managedObjectContext question...
        Posted  
        
            by treasure
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by treasure
        
        
        
        Published on 2010-05-12T09:38:20Z
        Indexed on 
            2010/05/12
            10:04 UTC
        
        
        Read the original article
        Hit count: 226
        
Hello,
I have an app which is a UITabBarController, I have defined two subviews
Both tabs have their Class attribute in the Identity Inspector set to UINavigationController.
Now i have managed to get this far with my coding after VERY LONG trials.
- (void)viewDidLoad {
[super viewDidLoad];
myAppDelegate *appDelegate = (myAppDelegate *)[[UIApplication sharedApplication] delegate];
self.managedObjectContext = appDelegate.managedObjectContext;
{
  NSError *error = nil;
  NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
  [fetchRequest setEntity:[NSEntityDescription entityForName:@"User" inManagedObjectContext:self.managedObjectContext]];
  NSArray *fetchedItems = [self.managedObjectContext executeFetchRequest:fetchRequest error:&error];
  NSEntityDescription *entityDesc =
  [NSEntityDescription entityForName:@"User" inManagedObjectContext:self.managedObjectContext];
  // replace the old data with new. this DOESNT WORK
  if (fetchedItems.count > 0)
  {
   Usr *newUsr;
   for (newUsr in fetchedItems)
   {
    if ([newUsr.name isEqualToString:@"Line One"])
    {
     newUsr.uName = @"Line One (new)";
    }
   }
  }
  //add a new default data. THIS ADDS DATA TO MY TABLEVIEW BUT IT DOESNT SAVE THEM TO THE SQLITE
  User *addedDefaultdata = nil;
  addedDefaultdata = [[User alloc] initWithEntity:entityDesc insertIntoManagedObjectContext:self.managedObjectContext];
  addedDefaultdata.name = @"Added new 1";
  [addedDefaultdata release];
 }
  NSError *error = nil;
 if (![[self fetchedResultsController] performFetch:&error]) {
  NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
  abort();
 }
}
and my appdelegate looks like this:
- (void)applicationDidFinishLaunching:(UIApplication *)application {    
 [application setStatusBarStyle:UIStatusBarStyleBlackOpaque];
 [window addSubview:navigationController.view];
 [window makeKeyAndVisible];
}
now I cannot quire the "User" at all! although i get no errors or warnings!
Any suggestions would be much appreciated!
Thanks
© Stack Overflow or respective owner