将值从弹出式VC传递到控制器



当前在我的应用程序中,我正在普通视图控制器中打开一个弹出视图控制器,需要将值从弹出VC传递回普通VC。

这就是我制作弹出窗口的方式。

let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "IconEditPopup") as! IconEditPopup
// this is where you can set values in the view
vc.id = "12"
self.addChild(vc)
vc.view.frame = self.view.frame
self.view.addSubview(vc.view)
vc.didMove(toParent: self)

基本上只是想把值从弹出视图控制器传递回我的普通VC.

您可以使用Delegate模式或Clouser回调处理程序将值传递回父视图。

这里有一个例子:

在popVC中定义一个clouser,如下所示:

var clouserName: ((returnType) -> Void)?

在您的popVC中,您需要调用clouser:

clouserName?(returnValue)

在您的父控制器中,以这种方式捕获值:

vc.clouserName = { returnValue in // dont forget [weak self] if you need self
// Do your stuff here
}

相关内容

最新更新