ios – 将数据从模态segue传递给父级

我想将数据(例如set var)从modal segue传递给parent,我该怎么做?

我正在使用该代码退出模态segue:

@IBAction func doneClicked(sender: AnyObject) {
    self.dismissViewControllerAnimated(true,completion: nil)
}

我不能在这里使用segue.destinationViewController传递数据,就像我以前在push segues上做的那样.

解决方法

在Modal ViewController上创建协议
protocol ModalViewControllerDelegate
{
    func sendValue(var value : Nsstring)
}

同样在你的Modal ViewController类中声明

var delegate:ModalViewControllerDelegate!

在ParentViewController中包含此协议ModalViewControllerDelegate

当您从一个viewController移动到另一个viewController时

modalVC.delegate=self;
        self.presentViewController(modalVC,animated: true,completion: nil)

在这里,您可以在ParentViewcontroller中获得您的价值

func sendValue(value: Nsstring) {

    }

最后在ModalViewController上

@IBAction func doneClicked(sender: AnyObject) {
delegate?.sendValue("value")
    self.dismissViewControllerAnimated(true,completion: nil)
}

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...