I have used NSNotifications before, but this is the first time I have tried using KVO in Cocoa Touch.
My UITableView controller switches between different data sources, so I encapsulated them in different subclasses of UITableViewDataSource. I try to have my view controller observe a specific one of these subclasses of UITableViewDataSource and track an enumeration called loadState that reflects load state models.
I set the observer as follows:
[self.siteUpdatesDataSource addObserver:self forKeyPath:@"loadState" options:0 context:nil];
From the debugger, I see that the observer is registered:
(gdb) po [self siteUpdatesDataSource] <SiteUpdatesTableViewDataSource: 0x651e5a0> Current language: auto; currently objective-c (gdb) po [[self siteUpdatesDataSource] observationInfo] <NSKeyValueObservationInfo 0x651dd70> ( <NSKeyValueObservance 0x651dd10: Observer: 0xc80f1e0, Key path: loadState, Options: <New: NO, Old: NO, Prior: NO> Context: 0x0, Property: 0x651dd90>
)
However, my watchValueForKeyPath method is never called in my viewController. I set a breakpoint and nothing ever reaches it, even when I confirm that the listing has changed.
- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { [self.tableView reloadData]; }
I appreciate any thoughts about what I am missing.
Nick
source share