简体   繁体   English

如何在swift中解除父母的弹出窗口

[英]How to dismiss a popover from parent in swift

I am new to iOS and swift. 我是iOS和swift的新手。 I'm trying to show a popover. 我正试图展示一个弹出窗口。 I have managed to show a popover but the problem is I need to dismiss it from the parent. 我设法显示一个弹出窗口,但问题是我需要从父母那里解雇它。

I can dismiss the popover from the ViewController itself using this code 我可以使用此代码从ViewController本身中删除popover

self.dismissViewControllerAnimated(true, completion: nil)

But I need to do this from the parent view controller. 但我需要从父视图控制器执行此操作。

I have done this so far. 到目前为止我已经这样做了。 On button click performSegueWithIdentifier("bookingPopOverSegue", sender: self) 在按钮上单击performSegueWithIdentifier(“bookingPopOverSegue”,sender:self)

on prepareForSegue, 在prepareForSegue上,

if segue.identifier == "bookingPopOverSegue" {

        var bookingViewController = segue.destinationViewController as! BookingViewController
        var passthroughViews: [AnyObject] = self.timeSlotButtons
        passthroughViews.append(self.scrollView)
        bookingViewController.popoverPresentationController?.passthroughViews = passthroughViews
    }

Any idea on how to do this? 有关如何做到这一点的任何想法? Any help would be appreciated.. 任何帮助,将不胜感激..

Just call dismiss method using parent's presentedViewController property, like .... 只需使用parent的presentViewController属性调用dismiss方法,就像....

self.presentedViewController.dismissViewControllerAnimated(true, completion: nil)

For Swift 3.0 对于Swift 3.0

self.presentedViewController?.dismiss(animated: true, completion: nil)

If your popover controller is made public (for instance as a property of your child view controller), then just use it: 如果弹出控制器是公共的(例如作为子视图控制器的属性),那么只需使用它:

// 'self' is the parent
// 'popoverController' is the name of the property
self.childViewController.popoverController.dismissPopoverAnimated(<true or false>)

In other words, the problem is not the popover, it is its visibility from the parent. 换句话说,问题不在于弹出,而是从父级的可见性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM