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

后端 未结 3 1524
醉话见心
醉话见心 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: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.

提交回复
热议问题