简体   繁体   English

保存核心数据时出现问题!

[英]Problem with saving with Core Data!

I have an iPhone application, which lets the user add and and modify Assignments. 我有一个iPhone应用程序,它使用户可以添加和修改作业。 Each Assignment entity is has a relationship with another entity: Course. 每个工作分配实体与另一个实体都有一个关系:课程。 When the user adds a new Assignment, he has to choose a Course. 用户添加新任务时,他必须选择一个课程。 So far, so good. 到现在为止还挺好。

But the list of available courses is editable, so while the user is adding an Assignment, he can also create and edit the courses. 但是可用课程列表是可编辑的,因此在用户添加作业时,他还可以创建和编辑课程。 The problem is, when he saves a new Course, the Assignment is also saved, so even if he then presses cancel at the "Add Assignment" view, the Assignment is alredy saved... Since entities with relationships need to be in the same context, I can't create a new context just for the courses. 问题是,当他保存新课程时,任务分配也会保存,因此即使他随后在“添加任务”视图中按“取消”,任务分配也会被保存...因为具有关系的实体需要位于同一位置上下文,我不能只为课程创建新的上下文。

Is there any way to save the courses separately? 有什么办法可以分别保存课程吗?

Instead of throwing away the context when the user hits cancel, just delete the newly created assignment. 无需删除用户单击“取消”时的上下文,只需删除新创建的任务即可。 After deleting the assignment entity, check if there are any changes (meaning the user added courses) and save the context. 删除作业实体后,检查是否有任何更改(意味着用户已添加课程)并保存上下文。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM