ios - Swift - 如何从 ModalPopupController 重新加载 ViewController

标签 ios swift uiviewcontroller modalviewcontroller

我有 2 个 ViewController,一个名为 FirstViewController,它包含一个 UIImage 和一个 UIButton,第二个名为 ModalPopupViewController,它包含 2 个按钮

所以在我的 FirstViewController 上,当我按下 UIButton 时,它会在当前上下文中进行“Cross Dissolve”转换
在 ModalPopupViewController 上,当我按下第一个按钮时,我选择了一张带有 UIImagePickerController 的图片并保存它,当我按下第二个按钮时我关闭了 View ,但我的图片仅在我重新启动我的应用程序时出现。
我怎么能当我离开 ModalPopupViewController 时重新加载我的 FirstViewController?

我尝试调用 viewWillAppearviewDidAppear 但是当我从 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/

相关文章:

iphone - 多个 UIViewController 子类中的相同 UIView 子类?

ios - 使用 sysctl 检测当前在 iOS 上运行的应用程序

ios - 更改 @State 变量不会更新 SwiftUI 中的 View

ios - 是否可以强制我的 iOS 应用程序仅使用某种类型的 UILocalNotification?

swift - SpriteKit - 在 SKAction 期间正确定位 Sprite

ios - 在另一个类中设置 TextView 的文本不起作用

ios - 如何取消选中tableView中的选中行

ios - header 搜索路径麻烦 Grabkit

ios - 如何处理从 HTTP GET 请求返回的 JSON - Swift?

ios - 关闭 UIPopoverController 不会卸载 contentController