微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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)
}

原文地址:https://www.jb51.cc/iOS/332943.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐