I am fairly new to ipad and split view but quite familiar with iphone and core data. And I am wondering now when to actually save any changes so that no changes get lost and saving the context is not called too often.
The user selects an item from the master view which is then displayed in the detail view controller. Pretty similar to iPhone. But within a split view the detail view controller simply remains visible and is assigned a new detail item every time when a new one is selected by in the master.
Question: In the meantime the user may have made changes to the detail item. When to save those? To which event could I react? setDetailItem is a good place to save changes to the old detailItem before the new one is displied. Fine. But what is with changes to the very last item before the user quits the app?
To add some complexity to this: I am running several split view controllers within a TabBar. So the user may switch from one tab bar to the next. I guess that viewWillDisappear
may be suitable to control those events? Should I save the last changes there too? Is it called upon leaving the app too?
setDetailItem
and viewWillDisappear
sound good to me for saving the user data.
viewWillDisappear
is not called when the application goes into background, but applicationDidEnterBackground
in the application delegate is called.
According to the documentation,
... You should use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. ...
Alternatively, you can register for the UIApplicationDidEnterBackgroundNotification
.