我有 2 个 ViewController,一个名为 FirstViewController,它包含一个 UIImage 和一个 UIButton,第二个名为 ModalPopupViewController,它包含 2 个按钮
所以在我的 FirstViewController 上,当我按下 UIButton 时,它会在当前上下文中进行“Cross Dissolve”转换
在 ModalPopupViewController 上,当我按下第一个按钮时,我选择了一张带有 UIImagePickerController 的图片并保存它,当我按下第二个按钮时我关闭了 View ,但我的图片仅在我重新启动我的应用程序时出现。
我怎么能当我离开 ModalPopupViewController 时重新加载我的 FirstViewController?
我尝试调用 viewWillAppear
和 viewDidAppear
但是当我从 ModalPopupViewController 返回到 FirstViewController 时没有附加内容
最佳答案
你可以使用委托(delegate)模式
protocol ReloadManager {
func reloadImageV(image:UIImage)
}
当你呈现模态时
let modal = ///
modal.delegate = self
present(modal//////
class FirstVC:UIViewController , ReloadManager {
func reloadImageV(image:UIImage) {
// reload here
}
}
class ModalVC:UIViewController {
var delegate:ReloadManager?
@IBAction func btnClicked(_ sender:UIButton) {
delegate?.reloadImageV(image: sendedImage)
dismiss(animated: true, completion: nil)
}
}
//
删除 segue 并在导航到模态的 btn 操作中执行此操作,为模态提供 Storyboard标识符,将其转换为真正的模态类名
let vc = self.storyboard?.instantiateViewController(withIdentifier: "modalID") as! ModViewController
vc.delegate = self
vc.providesPresentationContextTransitionStyle = true;
vc.definesPresentationContext = true;
vc.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
self.present(vc, animated: false, completion: nil)
关于ios - Swift - 如何从 ModalPopupController 重新加载 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51231454/