当前视图控制器调用viewWillDisappear但不调用viewWillAppear。

3
以下是我展示Safari视图控制器的代码
 if let url = URL(string: "https://www.ggogle.com.com/") {
            let config = SFSafariViewController.Configuration()
            config.entersReaderIfAvailable = true
            let vc = SFSafariViewController(url: url, configuration: config)
            present(vc, animated: false)


        }

以上代码在呈现视图控制器被解除时调用了viewWillDisappear,但没有调用viewWillAppear。

还发现,在视图被解除后,对于任何其他pushViewController,都不会调用viewWillDisappear。

如何修复这个问题?

关于此更新:

尝试使用导航控制器并设置其委托,并实现以下方法

navigationController:willShowViewController:animated:
navigationController:didShowViewController:animated:

这也不起作用。

对于此问题的更新,尝试以下代码:

  vc.modalPresentationStyle = .currentContext

但是使用这个选项卡栏时,控制器不会隐藏且不会完全显示屏幕,也没有类似于在展示中隐藏底部栏的选项。

当一个视图控制器被解散时,父视图控制器的ViewWillAppear方法不会被调用。我们可以使用委托或解散方法的完成来解决这个问题。 - Pawan Kumar
更新问题:还发现在视图被解散后,对于任何其他pushViewController,viewWillDisappear根本没有被调用。 - amodkanthe
一个好的阅读材料。 - cora
关闭一个控制器不会调用被关闭控制器的viewWillAppear方法,但它会调用即将显示在被关闭控制器后面的控制器的viewWillAppear方法。 - Abu Ul Hassan
1个回答

0
请尝试这个。
 if let url = URL(string: "https://www.google.com/") {
            let config = SFSafariViewController.Configuration()
            config.entersReaderIfAvailable = true
            let vc = SFSafariViewController(url: url, configuration: config)

            vc.modalPresentationStyle = .currentContext

            present(vc, animated: false)

        }

更新

vc.modalPresentationStyle = .currentContext
tabBarController?.present(viewController, animated: false, completion: nil)

这也会导致问题,同时它也不能隐藏选项卡栏。 - amodkanthe

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接