gpt4 book ai didi

ios - View Controller 到达前端时必须刷新自身

转载 作者:行者123 更新时间:2023-11-29 05:36:30 25 4
gpt4 key购买 nike

我正在使用 Swift 4.0 开发一个应用程序。我有一个 View Controller ,在上面显示一些有用的信息,用户可以与它们交互。我们将其称为 BaseViewController。

我在做什么:BaseViewController 正在启动不同的其他 ViewController,并且用户可以关闭这些 viewController 并返回到 BaseViewController。

我想要什么:现在我希望每当用户返回 BaseViewController 时它都会得到更新。我知道可以使用协议(protocol)来完成,但我只想要一种简单的方法。就像在 Android 中一样,每当 Activity 进入事件状态时,都有 onResume 方法来执行更新。

我认为没有必要共享代码,因为从一个 View Controller 启动其他 View Controller 非常简单。我只是想知道更好的方法。提前致谢

更新:这就是我通过基础 Controller 调用下一个 Controller 的方式

let dialogRegisterForEventVC = UIStoryboard(name: "Main",bundle: nil).instantiateViewController(withIdentifier: "idDialogRegisterForEventVC") as! DialogRegisterForEventVC
dialogRegisterForEventVC.modalPresentationStyle = .overCurrentContext
dialogRegisterForEventVC.modalTransitionStyle = .crossDissolve
dialogRegisterForEventVC.isUserLogin = isLogin

self.present(dialogRegisterForEventVC, animated: true) {

}

最佳答案

您可以随时选择 viewWillAppear方法

override func viewWillAppear(_ animated: Bool) {
print("This is called when coming back to Base View Controller")
}

在此处使用您的刷新代码。当您弹出 viewController

时会调用此函数

关于ios - View Controller 到达前端时必须刷新自身,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56990712/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com