Nono Nono - 1 year ago 86
iOS Question

iOS - NSInternalInconsistencyException (Table Search)

I want to do an iOS App with a Table Search with Objective-C. I have tried this project:

Now I have tried to set a normal view between the navigation view and the table view. On the normal view is a button which have a push segue to the table view.

When I push this button I come to the table view and the search is still working. But if I use the back button now, the app crashes with the following message:

2016-05-19 23:23:29.135 Table Search[2533:63871] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'An instance 0x7f81b95db6e0 of class MainTableViewController was deallocated while key value observers were still registered with it. Current observation info: <NSKeyValueObservationInfo 0x7f81b945c000> (
<NSKeyValueObservance 0x7f81b9428720: Observer: 0x7f81b95e9830, Key path: results, Options: <New: YES, Old: NO, Prior: NO> Context: 0x0, Property: 0x7f81b94286f0>

Do someone know what is wrong here? Would be nice if you can have a look into this project.

Answer Source

You need to remove observers from your key value observing before MainTableViewController is deallocated. You can do this by overriding dealloc. You should add:

- (void)dealloc
    [self removeObserver:self.controller.searchResultsController forKeyPath:@"results"];

to MainTableViewController.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download