【问题标题】:Present UISearchBar results as UIPopoverPresentationController iOS 9将 UISearchBar 结果显示为 UIPopoverPresentationController iOS 9
【发布时间】: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。

【问题讨论】:

    标签: ios swift popover ios9


    【解决方案1】:

    您需要做的是实现以下属于UIPopoverPresentationControllerDelegate 协议的方法:

    - (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller {
        return UIModalPresentationNone; // This will force a popover display
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-05
      • 1970-01-01
      • 1970-01-01
      • 2012-06-04
      • 1970-01-01
      相关资源
      最近更新 更多