是否可以检测是否因为按下后退按钮而出现视图。例如,使用此层次结构VC1 -> webViewController -> VC3
,如果在VC3
我按下后退按钮,我想在webViewController
出现时检测到。我的目标是在shouldStartLoadWith
方法中使用它,以避免在按下后退按钮时刷新页面。
答案 0 :(得分:0)
请在webViewController
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
//This Check is for if still webview is Loading the page or content
if (webView.isLoading) {
NSLog(@"your webview is still loading");
return;
}
else {
//this is for when its finish loading
NSLog(@"your webview is loaded completely");
}
}
答案 1 :(得分:0)
您可以使用closure
进行此类回调。
示例强>:
class WebViewController: UIViewController
{
@IBAction func onTapButton(_ sender: UIButton)
{
let controller = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "VC3") as! VC3
controller.completionHandler = {
//Code to execute after back button is pressed.
}
self.navigationController?.pushViewController(controller, animated: true)
}
}
class VC3: UIViewController
{
var completionHandler : (()->())?
override func viewWillDisappear(_ animated: Bool)
{
if self.navigationController?.viewControllers.index(of: self) == nil
{
//Back Button pressed
self.completionHandler?()
}
super.viewWillDisappear(animated)
}
}