Disable persistence of a given NSManagedObject until user hits a button?
I have an NSManagedObject with attributes that a user can edit with a view. The view is populated with the values from the object, the user can edit the values, and the values are written back to the object. I want the user to explicitly tap a save or cancel button to commit or undo the changes.
The problem is that the view is in a UITabbarController where other开发者_运维知识库 things are going on. The user might perform operations in another tab where [NSManagedObjectContext save] or [NSManagedObjectContext undo] might get called. This would affect the NSManagedObject (from the first mentioned tab) before the user decides if they want to save or cancel it.
Is there a way around this? Can we temporarily disable persistence on an NSManagedObject until the user taps the button?
There is no way to disable persistence for a managed object. Instead I would recommend an approach like this:
Typically, when showing a view that edits a particular object, you update that view with the data from the object in the viewWillAppear:
method and update the object with the changed data in a corresponding "save" action or viewWillDisappear:
.
精彩评论