Note that there are some explanatory texts on larger screens.

plurals
  1. POCore Data Edit/Save Attributes in an Entity
    primarykey
    data
    text
    <p>I am struggling with the editing/saving in Core Data and need some help in this. I am using NSFetchedResultsController and have an entity named Golfer with attributes- first_name, last_name, email_id and others in Core Data. So, I know how to add and remove golfers from the database.</p> <p>I am working on one view controller called ViewManager (kinda base view for all my classes) and it has 2-3 Custom UIViews inside it. I animate them in and out whenever I need them.</p> <p>I add a golfer to the tableview, then on didSelectRow tableview method, I present my edit View inside the same ViewManager controller and try to update the textfields in the edit view using the following code, but it's updating at random indexes in the tableview and not working for me. Any help would be greatly appreciated.</p> <pre><code>- (IBAction)saveEditGolfersView:(id)sender { AppDelegate * applicationDelegate = (AppDelegate *) [[UIApplication sharedApplication] delegate]; NSManagedObjectContext * context = [applicationDelegate managedObjectContext]; // Retrieve the entity from the local store -- much like a table in a database NSEntityDescription *entity = [NSEntityDescription entityForName:@"Golfer" inManagedObjectContext:context]; NSFetchRequest *request = [[NSFetchRequest alloc] init]; [request setEntity:entity]; // Set the sorting -- mandatory, even if you're fetching a single record/object NSSortDescriptor *sortDescriptor1 = [[NSSortDescriptor alloc] initWithKey:@"first_name" ascending:YES]; NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor1,nil]; [request setSortDescriptors:sortDescriptors]; [sortDescriptors release]; sortDescriptors = nil; [sortDescriptor1 release]; sortDescriptor1 = nil; NSError * error; NSArray * objects = [context executeFetchRequest:request error:&amp;error]; for(int i = 0; i&lt;[objects count]; i++) { Golfer * golfguy = [objects objectAtIndex:i]; golfguy.first_name = mEditFirstName.text; golfguy.middle_name = mEditMiddleName.text; golfguy.last_name = mEditLastName.text; golfguy.email_id = mEditEmailField.text; golfguy.contactNumber = mEditContactNum.text; golfguy.picture = mEditPictureView.image; NSLog(@"name-%@", golfguy.first_name); } [request release]; request = nil; error = nil; [context save:&amp;error]; [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^ { mEditGolfersView.frame = CGRectMake(-480, mEditGolfersView.frame.origin.y, mEditGolfersView.frame.size.width, mEditGolfersView.frame.size.height); } completion:^(BOOL finished) { mEditGolfersView.hidden = YES; }]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload