0

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

https://github.com/versluis/Table-Search-2015

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.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Nono
  • 1,073
  • 4
  • 23
  • 46

1 Answers1

1

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.

beyowulf
  • 15,101
  • 2
  • 34
  • 40
  • Ok the app no longer crashes, but now in the console appears the following message: Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior () Is that a problem or can I ignore that? – Nono May 19 '16 at 21:52
  • That's not related to your question. As it doesn't appear in the demo project I made using your link. Check the answers here: http://stackoverflow.com/questions/32282401/attempting-to-load-the-view-of-a-view-controller-while-it-is-deallocating-uis – beyowulf May 19 '16 at 22:18