Swift:Popover解雇回调

前端之家收集整理的这篇文章主要介绍了Swift:Popover解雇回调前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我的Storyboard中有两个UIViewConrollers:MainViewController和SecondViewController.当用户点击名为Show Popover的按钮时,我将把SecondViewController显示为弹出框:

//MainViewController
override func prepareForSegue(segue: UIStoryboardSegue,sender: AnyObject?)
{

    if segue.identifier == "GoToSecondViewControllerSegue"
    {
        var vc = segue.destinationViewController as! SecondViewController
        var controller = vc.popoverPresentationController

        if controller != nil
        {
            controller?.delegate = self
            vc.inputTextDelegate = "I'm a popover!"
        }
    }
}

func popoverPresentationControllerDidDismissPopover(popoverPresentationController: UIPopoverPresentationController) {
     println("done")
}

func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle
{
    return .None
}
//SecondViewController
@IBAction func dismissPopover(sender: UIButton) {
     dismissViewControllerAnimated(true,completion: nil)
     //This dismisses the popover but does not notify the MainViewConroller
}

segue的锚点连接到一个按钮:

现在我有两个问题:

>当我点击popover内的取消按钮时,它会解除弹出窗口但不会在MainViewController中触发popoverPresentationControllerDidDismissPopover
>我如何将数据从SecondViewController传递到MainViewController,例如UITextView的文本值.

或者,更简单地说,当您手动关闭弹出窗口时,只需手动调用iOS的委托方法.
dismissViewControllerAnimated(true,completion: nil)
    popoverPresentationController?.delegate?.popoverPresentationControllerDidDismissPopover?(popoverPresentationController!)
原文链接:https://www.f2er.com/swift/320228.html

猜你在找的Swift相关文章