本文介绍了如何将值从弹出视图控制器传递到上一个视图控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以在我的1stViewController中,我有以下代码:
So In my 1stViewController I have this code:
@IBAction func colorDropdown(_ sender: Any) {
self.popUpColorPicker()
}
func popUpColorPicker() {
let popOverVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "ColorPicker") as! ColorPicker
self.addChildViewController(popOverVC)
popOverVC.view.frame = self.view.frame
self.view.addSubview(popOverVC.view)
popOverVC.didMove(toParentViewController: self)
}
哪个会弹出2ndViewController.关闭弹出式2ndViewController后,我想检索输入的值并在我的第一个视图控制器中使用它.
Which would pop up the 2ndViewController. Upon dismissing the Pop Up 2ndViewController, I'd like to retrieve the values I entered and use it in my 1st View Controller.
推荐答案
您可以使用delegate
或completion handler
来实现.
只需创建一个委托来处理有关关闭second VC
的数据.
Just create a delegate to handle your data on dismissing the second VC
.
**
**
写一个completion handler
closure
以在您的第一个view controller
中取回那些值.
Write a completion handler
closure
to get back those values in your first view controller
.
这篇关于如何将值从弹出视图控制器传递到上一个视图控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!