gpt4 book ai didi

ios - 将 UISearchBar 结果呈现为 UIPopoverPresentationController iOS 9

转载 作者:行者123 更新时间:2023-11-30 14:03:22 25 4
gpt4 key购买 nike

我有一个带有 UISearchBar 的 ParentViewController 和一个带有 tableView 的 ChildTableViewController,其中将显示搜索结果。当我点击搜索栏时,弹出窗口应显示符合搜索栏上写入的过滤器的所有结果。这意味着,一开始,所有结果都应该显示在 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)

}

enter image description here

我使用的是 Xcode 7 和 iOS 9。

最佳答案

您需要做的是实现以下方法,该方法是 UIPopoverPresentationControllerDelegate 协议(protocol)的一部分:

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

关于ios - 将 UISearchBar 结果呈现为 UIPopoverPresentationController iOS 9,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32719402/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com