undo all changes made in a view controller

99封情书 提交于 2019-12-25 00:23:20

问题


Is it possible to undo all changes made in a view controller without affecting the changes made in its parent view controller? btw. They are with the same managedObjectContext. ps. I have two entities A and B. A has an to-many relationships to B. View controller VCA is used to perform some changes in A. View controller VCB is used to perform some changes in B. VCA is the parent view controller of VCB.


回答1:


No need to create a new context. When you leave the child view controller, you have the option of either

[managedObjectContext save:&error];

or

[managedObjectContext rollback];

In the latter case, all your new entity instances, data modifications etc. will be discarded.




回答2:


You should create new NSManagedObjectContext for child view controller and attach undo to it. NSManagedObjectContext is very light and doesn't cost very much.



来源:https://stackoverflow.com/questions/10400310/undo-all-changes-made-in-a-view-controller

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