Attempting to load the view of a view controller while it is deallocating… UISearchController

UISearchController’s view has to be removed from its superview before deallocate. (guess it is a bug)

Objective-C…

-(void)dealloc { 
    [searchController.view removeFromSuperview]; // It works!
}

Swift 3…

deinit {
    self.searchController.view.removeFromSuperview()
}

I struggled with this issue for a couple of weeks. ^^

Leave a Comment