【发布时间】:2015-10-28 09:10:19
【问题描述】:
我在导航栏中有一个UISearchController,它一直运行良好。
仅在 iOS 9 上,搜索栏在控制器加载后拒绝成为第一响应者。
viewDidLoad中的代码:
self.searchController = ({
let controller = UISearchController(searchResultsController: nil)
controller.searchResultsUpdater = self
controller.delegate = self
controller.dimsBackgroundDuringPresentation = false
let ownSearchBar = controller.searchBar
ownSearchBar.searchBarStyle = .Default
ownSearchBar.barStyle = UIBarStyle.Black
ownSearchBar.placeholder = NSLocalizedString("Search", comment: "Search")
ownSearchBar.showsCancelButton = true
ownSearchBar.sizeToFit()
ownSearchBar.delegate = self
controller.searchBar.delegate = self
controller.hidesNavigationBarDuringPresentation = false
self.navigationItem.titleView = controller.searchBar
self.navigationItem.hidesBackButton = true
self.navigationController?.navigationBar.sizeToFit()
return controller
})()
viewDidAppear 中的代码:
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
self.searchController.active = true
self.searchController.searchBar.text = state.term
self.segmentedControl.selectedSegmentIndex = state.searchType
}
还有我在didPresentSearchController中的代码:
extension SearchController : UISearchControllerDelegate {
func didPresentSearchController(searchController: UISearchController){
self.searchController.searchBar.becomeFirstResponder()
xButtonWasPressed = true
}
}
请帮我找出为什么只有在 iOS 9 中搜索栏没有获得焦点
【问题讨论】:
-
你在看模拟器还是readl设备?
-
我都签入了。设备是 iPhone 6
-
对我来说同样的问题。认为这是一个错误...... :(
-
也得到了这个错误,在 iOS8 中一切正常 :(
标签: swift uisearchbar ios9 uisearchcontroller becomefirstresponder