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

后端 未结 3 1499
醉话见心
醉话见心 2020-12-31 11:09

I have two view controllers A and B. From A, I navigate to view controller B as follows:

// in View Controller A 
// navigateToB method

-(void) navigateToB          


        
相关标签:
3条回答
  • 2020-12-31 11:44

    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.

    0 讨论(0)
  • 2020-12-31 11:46

    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.

    0 讨论(0)
  • 2020-12-31 11:57

    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.

    0 讨论(0)
提交回复
热议问题