Let's assume I have an address book App. So from the address list I now push to a detail view like so:
showDetail
is invokedprepareForSegue:
I set the model object contact
of my ContactDetailViewController
viewWillAppear
I add an observer for self.contact
contact
object changes in the background, the detail view will automatically be updated.viewWillDisappear
I remove this observer (I guess it's clean because it is symetrical).However, viewWillAppear:
is called after I set the contact. So should I setup the KVO differently or simply call my updateView
function in viewWillAppear
which is a bit stupid because I want to get rid of those calls with KVO in the first place.
When you call addObserver:...
you want to include the option NSKeyValueObservingOptionInitial
. This will cause KVO to send the equivalent of a didChangeValueForKey:
notification (i.e. an "Initial" notification) in the same call that adds the observation. This should cause your view to update at that time.