allaire
allaire

Reputation: 6045

Core data, validateForInsert: / validateForUpdate: create an entity even when they cancel

iPhone forms, where do you put your validation?

People suggested me to directly put the value of my textfields in my core data entity, which I did (see my second edit). Thing is, when a person update an entity, since I put directly the value that the user is typing in my entity, even when I don't save my ManagedObjectContext, my TableViewController (using NSFRC) updates with the latest infos the user entered (even if he pressed cancel). If I restart the app, since it didnt save, everything is back to normal.

How can I avoid this?

Upvotes: 2

Views: 1070

Answers (1)

Gobot
Gobot

Reputation: 2480

I'm assuming you are using the same NSManagedObjectContext for both viewControllers. You could use a separate NSManagedObjectContext for each viewController. If you are using iOS 5.1 set the 1st viewController's managedObjectContext (MOC) as the parent of the 2nd viewControllers managedObjectContext. So if you save the 2nd view's MOC via [theContext save], it will merge the changes with the 1st MOC automagically. If you don't want to keep the changes simply pop that view off the navigation stack.

MOC's are scratchpads. So in essence you want to use that 2nd viewController as a scratch pad, until you hit save.

Upvotes: 5

Related Questions