【发布时间】:2015-09-22 14:19:28
【问题描述】:
我有一个带有 UISearchBar 的 ParentViewController 和一个带有 tableView 的 ChildTableViewController,其中将显示搜索结果。当我点击 searchBar 时,应该会出现一个弹出框,其中包含符合 searchBar 上编写的过滤器的所有结果。这意味着,一开始,所有结果都应该显示在 popoverController 中。
问题是结果显示在整个屏幕上,而不是显示在弹出窗口中。下面是 ParentViewController 对应的代码,应该在其中显示弹出框。
func searchBarTextDidBeginEditing(searchBar: UISearchBar) {
let childController = ChildTableViewController()
childController.modalPresentationStyle = .Popover
childController.preferredContentSize = CGSize(width: 50, height: 100)
let popover = childController.popoverPresentationController
popover?.permittedArrowDirections = .Any
popover?.delegate = self
popover?.sourceView = self.view
popover?.sourceRect = CGRect(x: 200, y: 200, width: 1, height: 1)
presentViewController(childController, animated: true,completion: nil)
}
我正在使用 Xcode 7 和 iOS 9。
【问题讨论】: