Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior (<UISearchController

使用UISearchController出现这个警告

只要返回上一个界面就会报这个警告,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];就好了

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容