![](/img/trans.png)
[英]Going back to first ViewController from second 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.