我有一个UITableViewController显示为弹出窗口,如下所示
popoverViewController = self.storyboard?.instantiateViewController(withIdentifier: "ItemsTableView") as? ItemsTableViewController
popoverViewController?.itemeSelectionDelegate = self
popoverViewController?.modalPresentationStyle = .popover
let popoverPresentationViewController = popoverViewController?.popoverPresentationController
let itemCell = cell as! ItemContentCell
popoverPresentationViewController?.permittedArrowDirections = UIPopoverArrowDirection.any
popoverPresentationViewController?.sourceView = cell
popoverPresentationViewController?.sourceRect = itemCell.itemName.bounds
present(popoverViewController!, animated: true, completion: nil)
popoverViewController是一个成员var,我用它来关闭当从popoverViewController中选择一个项目时,我正在调用一个自定义委托方法,我从中解雇它使用“Dismiss”方法但它有时候工作有时它不会。
func itemSelected(item: Item) {
print("selected item")
popoverViewController?.dismiss(animated: false, completion: nil)
}
还有其他方法可以解雇popover吗?
答案 0 :(得分:0)
您必须实施UIPopoverPresentationControllerDelegate
方法public func popoverPresentationControllerShouldDismissPopover(_ popoverPresentationController: UIPopoverPresentationController) -> Bool
。
这是演示实现。
extension YouViewController: UIPopoverPresentationControllerDelegate {
func popoverPresentationControllerShouldDismissPopover(_ popoverPresentationController: UIPopoverPresentationController) -> Bool {
return true
}
}