gpt4 book ai didi

ios - 当 UIViewController 重新获得焦点时调用什么函数?

转载 作者:搜寻专家 更新时间:2023-11-01 06:27:31 24 4
gpt4 key购买 nike

我有一个单一 View 应用程序,它还显示了一个自定义弹出窗口,这是我使用另一个 viewController 制作的。弹出 View Controller 分配了以下内容:

 presentation: Over current context

enter image description here

出现时。当我关闭此弹出式 viewController 以显示第一个 viewController 时,我想知道调用了哪个函数,以便我可以在该函数中做更多的事情。我已经在下面测试了以下函数,但是当我关闭弹出窗口以显示第一个 viewController 时,它们都没有被调用。

class firstViewController: UIViewController {

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

print("viewWillAppear PdfViewController...")
}


override func viewDidLoad() {
super.viewDidLoad()

print("viewDidLoad PdfViewController ...")
}
}

最佳答案

这取决于 overCurrentContext 不调用 viewWillAppear/viewDidAppear 的样式,例如 fullScreen 调用,在这里寻找所有可能的风格

https://developer.apple.com/documentation/uikit/uimodalpresentationstyle

如果选择的没有调用该方法,则在您关闭模态时为其实现委托(delegate)

//

protocol DimissManager {
func vcDismissed()
}
class FirstVc:UIViewController,DimissManager {

func vcDismissed() {
print("Dismissed")
}
func showSecond() {
let sec = storyboard
sec.delegate = self ...... // note this assign may be in prepareForSegue if you use segues
self.present(sec.......
}
}
class SecondVc:UIViewController{
var delegate:DimissManager?

@IBAction func dismiss(_ sender:UIButton) {
delegate?.vcDismissed()
self.dismiss(animated:true,completion:nil)
}
}

关于ios - 当 UIViewController 重新获得焦点时调用什么函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52059005/

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