Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/97.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 从父ViewController来回时防止WKWebview重新加载_Ios_Swift_Uinavigationcontroller_Wkwebview - Fatal编程技术网

Ios 从父ViewController来回时防止WKWebview重新加载

Ios 从父ViewController来回时防止WKWebview重新加载,ios,swift,uinavigationcontroller,wkwebview,Ios,Swift,Uinavigationcontroller,Wkwebview,我的应用程序中有两个ViewController,它们嵌入在NavigationController中 var other: SecondViewController? 在第一个ViewController中有一个按钮,可将其推到第二个ViewController。在第二个ViewController中,我有WKWebView,它打开一个特定的URL 每次用户在第二个ViewController重新加载中来回浏览网站时 我只想打开它一次(第一次),当用户来回移动时,可以防止它重新加载(

我的应用程序中有两个
ViewController
,它们嵌入在
NavigationController

    var other: SecondViewController?
在第一个
ViewController
中有一个按钮,可将其推到第二个
ViewController
。在第二个
ViewController
中,我有WKWebView,它打开一个特定的URL

每次用户在第二个
ViewController
重新加载中来回浏览网站时

我只想打开它一次(第一次),当用户来回移动时,可以防止它重新加载(这样用户就不会丢失所有提供的数据,例如表单中的数据)。我怎样才能做到这一点


我可以阻止第二个
视图控制器从导航堆栈中删除吗?

我假设您正在创建一个新的
视图控制器或重新加载它。解决此问题的一种方法是保存对第二个
ViewController
的引用并重用它

假设第二个
ViewController
有类似的东西

    var other: SecondViewController?
你有一个前进到它的按钮

    @IBAction func buttonPressed(_ sender: Any) {
        if let otherVC = other {
            navigationController?.pushViewController(otherVC, animated: true)
        } else {
            other = SecondViewController(nibName: "SecondViewController", bundle: nil)
            if let other = other {
                navigationController?.pushViewController(other, animated: true)
            }
        }
    }
现在,如果你来回走,你就不会经历重新加载