[英]How to dismiss UIPopoverPresentationController on tap inside it. (iOS, Swift)
I've been successfully able to implement a popviewcontroller, which contains a tableview of 4 cells. 我已经成功实现了一个popviewcontroller,其中包含4个单元的表格视图。 I want to close the popViewController when the cell is selected, but I cannot seem to do this.
我想在选择单元格时关闭popViewController,但是我似乎无法做到这一点。 In my tableViewController, I have a method inside didSelectRowAtIndexPath, which calls this MasterViewController's method "updateToSelectedTab".
在我的tableViewController中,我在didSelectRowAtIndexPath内部有一个方法,该方法将该MasterViewController的方法称为“ updateToSelectedTab”。 I am able to print out the indexpath of the selected cell here, but I cannot remove the popViewController when the cell is selected.
我可以在此处打印出所选单元格的索引路径,但是当选中该单元格时,我无法删除popViewController。 How do I do this?
我该怎么做呢?
//Here is our MasterViewController class //这是我们的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.