【问题标题】:How to dismiss a popover from parent in swift如何迅速解除父母的弹出窗口
【发布时间】:2015-06-08 11:16:32
【问题描述】:

我是 iOS 新手,速度很快。我正在尝试显示一个弹出窗口。我设法显示了一个弹出框,但问题是我需要从父级中将其关闭。

我可以使用此代码从 ViewController 本身关闭弹出框

self.dismissViewControllerAnimated(true, completion: nil)

但我需要从父视图控制器执行此操作。

到目前为止,我已经这样做了。点击按钮 performSegueWithIdentifier("bookingPopOverSegue", sender: self)

关于prepareForSegue,

if segue.identifier == "bookingPopOverSegue" {

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

知道如何做到这一点吗?任何帮助将不胜感激..

【问题讨论】:

标签: ios swift delegates


【解决方案1】:

只需使用父级的presentedViewController 属性调用dismiss 方法,例如......

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

对于 Swift 3.0

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

【讨论】:

    【解决方案2】:

    如果您的弹出框 controller 是公开的(例如作为您的子视图控制器的属性),那么只需使用它:

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

    换句话说,问题不在于弹出框,而在于它对父级的可见性。

    【讨论】:

    • ViewController 没有名为“childViewController”的成员
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-01
    相关资源
    最近更新 更多