簡體   English   中英

防止 WKWebview 從父 ViewController 來回時重新加載

[英]Prevent WKWebview from reloading when going back and forth from parent ViewController

我的應用程序中有兩個ViewController ,它們嵌入在NavigationController中。

在第一個ViewController中有一個按鈕,它會推送到第二個ViewController 在第二個ViewController我有 WKWebView,它打開一個特定的 URL。

每次用戶來回移動時,第二個ViewController中的網站都會重新加載。

我只想打開一次(第一次),並且當用戶來回移動時會阻止它重新加載(因此用戶不會丟失所有提供的數據,表格中的 fe)。 我怎樣才能做到這一點?

我可以防止第二個ViewController從導航堆棧中刪除嗎?

我假設正在發生的事情是您正在創建一個新的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)
            }
        }
    }

現在,如果您來回 go,您將不會經歷重新加載。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM