UISearchDisplayController causes crash after viewDidUnload

后端 未结 7 1744
温柔的废话
温柔的废话 2020-12-14 09:50

I have a project using StoryBoards and UISearchDisplayController used in the context of a UINavigationController, that appears in the root viewcont

相关标签:
7条回答
  • 2020-12-14 10:46

    Here is what I did (granted, it's a workaround and not a fix for Apple's bug):

    First, in a base UIViewController I created a property called searchController:

    @property (nonatomic, retain) IBOutlet UISearchDisplayController* searchController;
    

    I added a UISearchBar in through interface builder so that I have a placeholder in my UI for it. Then, in my viewDidLoad I manually setup the controller and wire it up:

    UISearchDisplayController* searchController = [[UISearchDisplayController alloc] 
                                 initWithSearchBar:self.searchBar contentsController:self];
    searchController.searchResultsDataSource = self;
    searchController.searchResultsDelegate = self;
    searchController.delegate = self;
    
    self.searchController = searchController;
    [searchController release];
    

    In my viewDidUnload I make sure to clear it out:

    self.searchController = nil;
    
    0 讨论(0)
提交回复
热议问题