Bad_APPZ
Bad_APPZ

Reputation: 432

Core data edit function

I already have a tableView with data in it. IF you tap a cell/row it pushes to an edit type of view. Is there anyway to edit core data's data other than: By edit, i mean i already have data inserted into my context. I have loaded my data into my view, the user can change the existing data, and re save it.

.h

//Below is the entity/entity's class name 'Amm'

Amm *amm;

.m

 -(IBAction)save
{
[self.amm setValue:self.nameField.text forKey:@"name"];

[self.amm setValue:self.nicknameField.text forKey:@"nickname"];

[self.navigationController popViewControllerAnimated:YES];

NSError *error;

if (![self.managedObjectContext save:&error]) {

        //Handle Error
    }
}

I want this code to work, however the design pattern of my app isnt allowing this code to work for me as it does in other parts of my app. Thank you very much for any and all help!

Upvotes: 1

Views: 100

Answers (1)

Timbo
Timbo

Reputation: 1214

I assume from what you've said you have:

  • A table view listing your managed objects
  • A view where you can edit the values of a managed object
  • A save button bound to the save method

What's the actual issue? I'm assuming when you tap save that:

  • The values in self.nameField.text isn't setting self.amm.name
  • The values in self.nicknameField.text isn't setting self.amm.nickname

Is that right? If so perhaps try the following code to set the managed object values:

self.amm.name = self.nameField.text
self.amm.nickname = self.nicknameField.text

If that's not the issue and you are actually setting the managed object values properly, is it that you just need to refresh the table-view? Perhaps use some NSLog commands to log every step of the applications progress.

Upvotes: 1

Related Questions