CoreData 编辑/覆盖对象
我正在玩一个新项目,一个使用 Core Data 的分屏视图 iPad 应用程序,我想知道,因为它相当清楚如何添加和删除项目。如果我要说改变它来保存文本,那么该文本将显示在 UITextView
中,我如何编辑或覆盖 CoreData 中的对象?
因此,用户在 UITextView
中输入注释,当他们离开时,它会编辑并保存他们当前选择的注释(表视图中的对象)。
感谢任何帮助,谢谢。
I am playing around with a new project, a split view iPad app using Core Data, and I was wondering, as its fairly clear how to add and remove an item. If I was to say alter this to hold text, then that text be shown in a UITextView
, how can I edit or overwrite an object in CoreData?
So the user types their note in the UITextView
and when they leave that it edits and saves the note (object in the table view) they have currently selected.
Appreciate any help thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只需使用
NSFetchRequest
请求现有对象,更改需要更新的任何字段(只需要一个简单的 myObject.propertyName setter),然后执行 保存 操作关于数据上下文。编辑以添加代码示例。我同意 MCannon 的观点,核心数据绝对值得一读。
此代码假设您使用包含核心数据内容的模板创建了项目,以便您的应用程序委托具有托管对象上下文等。请注意,此处没有错误检查,这只是基本代码。
获取对象
更新对象
保存更改
现在您的对象/行已更新。
You simply request the existing object using an
NSFetchRequest
, change whatever fields need to be updated (a simple myObject.propertyName setter is all that's required), and then perform a save action on the data context.EDIT to add code example. I agree with MCannon, Core Data is definitely worth reading up about.
This code assumes you created the project with a template that includes Core Data stuff, such that your app delegate has a managed object context, etc. Note that there is NO error checking here, this is just basic code.
Fetching the object
Update the object
Save the change
Now your object/row is updated.
http://developer.apple.com/library /mac/documentation/Cocoa/Conceptual/CoreData/Articles/cdFetching.html 将向您展示如何获取实体,
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreData/Articles/cdUsingMOs.html 将向您展示如何更改属性并保存它们。
核心数据是你真正想要阅读大量苹果文档并熟悉的东西,从长远来看,它将节省你的时间。希望这有帮助!
http://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CoreData/Articles/cdFetching.html will show you how to fetch an entity,
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreData/Articles/cdUsingMOs.html will show you how to change properties, and save them.
core data is something where you really want to read a lot of the apple documentation and become familiar, it will save you hours in the long run. hope this helps!