![](/img/trans.png)
[英]Dismiss UIPopoverPresentationController with any gesture, not just tap
[英]How to dismiss UIPopoverPresentationController on tap inside it. (iOS, Swift)
我已经成功实现了一个popviewcontroller,其中包含4个单元的表格视图。 我想在选择单元格时关闭popViewController,但是我似乎无法做到这一点。 在我的tableViewController中,我在didSelectRowAtIndexPath内部有一个方法,该方法将该MasterViewController的方法称为“ updateToSelectedTab”。 我可以在此处打印出所选单元格的索引路径,但是当选中该单元格时,我无法删除popViewController。 我该怎么做呢?
//这是我们的MasterViewController类
@IBAction func pop(sender: AnyObject) {
let contentView = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("popViewController") as! PopViewController
contentView.modalPresentationStyle = UIModalPresentationStyle.Popover
contentView.preferredContentSize = CGSizeMake(aButton.frame.width, 240.0)
let popoverMenuViewController = contentView.popoverPresentationController!
popoverMenuViewController.delegate = self
popoverMenuViewController.permittedArrowDirections = UIPopoverArrowDirection.Any
popoverMenuViewController.sourceView = view
popoverMenuViewController.permittedArrowDirections = UIPopoverArrowDirection(rawValue:0)
popoverMenuViewController.sourceRect = CGRectMake(aButton.frame.origin.x, aButton.frame.origin.y - 60, aButton.frame.width, aButton.frame.height)
presentViewController(contentView, animated: true, completion: nil)
}
func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
return UIModalPresentationStyle.None
}
//This method is called from didSelectRowAtIndexPath of the View Controller that handles the UIPopoverPresentationController
func updateToSelectedTab(tab: Int){
print("Current tab \(tab)")
//Need to dismiss controller here
}
我要做的就是在索引路径委托方法的选择行中添加以下代码:
dismissViewControllerAnimated(true, completion: nil)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.