Core data edit function

谁说胖子不能爱 提交于 2021-01-28 09:23:41

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/13833063/core-data-edit-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!