在取消分配时尝试加载视图控制器的视图... UISearchController [英] Attempting to load the view of a view controller while it is deallocating... UISearchController
问题描述
我的代码在我的UIVIew的 viewDidLoad`中创建了一个 UISearchController。
I have code that creates a UISearchController' in my UIVIew's
viewDidLoad`.
self.resultSearchController = ({
let controller = UISearchController(searchResultsController: nil)
controller.searchResultsUpdater = self
controller.searchBar.delegate = self
controller.dimsBackgroundDuringPresentation = false
controller.searchBar.sizeToFit()
controller.hidesNavigationBarDuringPresentation = false //prevent search bar from moving
controller.searchBar.placeholder = "Search for song"
self.myTableView.tableHeaderView = controller.searchBar
return controller
})()
此关闭完成后,此警告会出现在控制台中:
Right after this closure finishes, this warning appears in the console:
Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior (<UISearchController: 0x154d39700>)
我不知道我做错了什么。 这个类似的问题并不是我的情况(至少我不知道)我想是这样的)。发生了什么?
I don't get what I am doing wrong. This similar question is not really my situation (At least I don't think so). What is going on?
推荐答案
在解除分配之前,必须从超级视图中删除UISearchController的视图。 (猜它是一个错误)
UISearchController's view has to be removed from its superview before deallocate. (guess it is a bug)
Objective-C ...
Objective-C...
-(void)dealloc {
[searchController.view removeFromSuperview]; // It works!
}
Swift 3 ...
Swift 3...
deinit {
self.searchController.view.removeFromSuperview()
}
我在这个问题上挣扎了几个星期。 ^^
I struggled with this issue for a couple of weeks. ^^
这篇关于在取消分配时尝试加载视图控制器的视图... UISearchController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!