Search code examples
iosobjective-cuitableviewuinavigationcontrollerdealloc

UITableview deallocation crashes with KVO error


I am using UITableview for a chat inbox view and my navigation stack is like

(
    "<VTDiscoverHome3ViewController: 0x7ff094758f00>",
    "<VTInboxViewController: 0x7ff098de34d0>",
    "<VTChatViewController: 0x7ff095827e00>",
    "<VTDiscoverProfessionalDetailsViewController: 0x7ff095424a00>",
    "<VTRequestScheduleViewController: 0x7ff095814c00>"
)

So while popping to home view from top view I am getting a crash in inbox view saying

An instance 0x7ff094a33800 of class UITableView was deallocated while key value observers were still registered with it. Current observation info: <NSKeyValueObservationInfo 0x608002e3f680> (
<NSKeyValueObservance 0x60800585c1d0: Observer: 0x7ff098f1b8d0, Key path: contentOffset, Options: <New: YES, Old: NO, Prior: NO> Context: 0x0, Property: 0x60800585c140>
<NSKeyValueObservance 0x60800585c320: Observer: 0x7ff098f1b8d0, Key path: contentSize, Options: <New: YES, Old: NO, Prior: NO> Context: 0x0, Property: 0x60800585c290>
<NSKeyValueObservance 0x60800585c410: Observer: 0x7ff098f1b8d0, Key path: frame, Options: <New: YES, Old: NO, Prior: NO> Context: 0x0, Property: 0x60800585c380>
<NSKeyValueObservance 0x60800585c500: Observer: 0x7ff098f1b8d0, Key path: contentInset, Options: <New: YES, Old: NO, Prior: NO> Context: 0x0, Property: 0x60800585c470>
)'

I tried removing tableview observers and setting

self.tableView.delegate = nil;
self.tableView.dataSource = nil;
self.tableView = nil;

but still no luck

I dont understand why am I getting this crash.

Any help would be much appreciable.

Thanks.


Solution

  • Got the solution.

    I am using a pull to refresh class which adds some observers to tableview's scrollview

    So while deallocation sometimes it was crashing.

    So, added try and catch block when removing observers.