How can UISearchDisplayController autorelease cause crash in a different view controller?

喜欢而已 提交于 2019-11-30 08:53:24

When you push a view controller onto a navigation controller, the navigation controller retains the view controller. And when that view controller is popped, the navigation controller releases it.

UISearchDisplayController appears to be trying to see if your view controllers responds to a selector, and since it's calling from _destroyManagedTableView, I'm guessing the selector is searchDisplayController:willUnloadSearchResultsTableView: (your view controller is the search display controller's delegate, correct?).

@robert - that example must be wrong, because pushViewController does retain its argument. All the other examples on the page either autorelease immediately after init, or release after pushing.

I had a similar problem solved by adding these lines to the dealloc method of my UITableViewController that was the delegate of the UISearchDisplayController:

self.searchDisplayController.delegate = nil;
self.searchDisplayController.searchResultsDelegate = nil;
self.searchDisplayController.searchResultsDataSource = nil;

I was slightly confused by the suggestion that to fix this issue the search display controller should be released in dealloc -- what you need to do is remove the pointers that the search display controller has to your table view controller since your table view controller is now going away and should not be called when your search display controller is later released. It's just like any other delegate reference that you want to nil out in dealloc.

I had the same issue. The searchDisplayController, was not made nil in the dealloc of the View controller, in which it was used. Instead the delegate managed the release of the searchDisplayController and this was done after, the tableView got released. Now after manually entering this code in the view controller's dealloc, its working fine now.

self.searchDisplayController.delegate = nil; self.searchDisplayController.searchResultsDelegate = nil; self.searchDisplayController.searchResultsDataSource = nil;

Thanks for your help.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!