Friday, October 02, 2009

UITableViewController and UIViewController don't handle observeValueForKeyPath:

In an iPhone 2.0 or greater app if you are seeing this error:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: ': An -observeValueForKeyPath:ofObject:change:context: message was received but not handled.

It might be because in YourClass's observeValueForKeyPath: method you are doing this:

// be sure to call the super implementation
// if the superclass implements it
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];

This could be because you saw in the Key-Value Observing Programming Guide those exact lines in the sample and didn't give it much thought.

If your base class doesn't implement observeValueForKeyPath:, like UITableViewController or UIViewController didn't, and you just assumed that the base class must even if it did nothing, like I did, then the above exception gets thrown.