使用UISearchController出現(xiàn)這個警告
只要返回上一個界面就會報這個警告,Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior ()
但是如果有點了一下搜索框再返回就不會報拌蜘,這個警告倒是不影響使用杆烁,但是看著不爽。简卧。
下面是我的相關的設置
- (void)viewDidLoad {
...
self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.searchResultsUpdater = self;
self.searchController.dimsBackgroundDuringPresentation = NO;
self.tableView.tableHeaderView = self.searchController.searchBar;
self.searchController.searchBar.searchBarStyle = UISearchBarStyleMinimal;
self.searchController.hidesNavigationBarDuringPresentation = NO;
self.definesPresentationContext = YES;
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
if (self.searchController.active) {
self.searchController.active = NO;
[self.searchController.searchBar removeFromSuperview];
}
}
解決方法
self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];改為 self.searchController = [[UISearchController alloc] initWithSearchResultsController:self];就好了