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)
}
}
}
现在,如果你来回走,你就不会经历重新加载