核心数据编辑功能 [英] Core data edit function

查看:39
本文介绍了核心数据编辑功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经有了一个包含数据的tableView.如果您点击一个单元格/行,它会推到 edit 类型的视图.无论如何,是否还有其他可以编辑核心数据的数据:通过编辑,我的意思是我已经将数据插入到上下文中.我已经将数据加载到视图中,用户可以更改现有数据,然后重新保存.

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

//下面是实体/实体的类名"Amm"

//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!

推荐答案

我假设您已经说过:

  • 列出您的托管对象的表视图
  • 一个视图,您可以在其中编辑托管对象的值
  • 绑定到save方法的保存按钮

实际问题是什么?我假设当您点击保存"时:

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

  • self.nameField.text中的值未设置self.amm.name
  • self.nicknameField.text中的值未设置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

如果这不是问题,而您实际上是在正确设置托管对象的值,那么是否只是需要刷新表视图?也许使用一些NSLog命令记录应用程序进度的每一步.

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.

这篇关于核心数据编辑功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆