0
是否有可能通过按下后退按钮来检测视图是否正在出现。例如对于这个层次结构,VC1 -> webViewController -> VC3
,如果在VC3
我按下后退按钮我想检测,当webViewController
出现。我的目标是在shouldStartLoadWith
方法中使用此方法,以避免在按下后退按钮时刷新页面。检测是否因为后退按钮被按下而加载视图
是否有可能通过按下后退按钮来检测视图是否正在出现。例如对于这个层次结构,VC1 -> webViewController -> VC3
,如果在VC3
我按下后退按钮我想检测,当webViewController
出现。我的目标是在shouldStartLoadWith
方法中使用此方法,以避免在按下后退按钮时刷新页面。检测是否因为后退按钮被按下而加载视图
请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");
}
}
使用此您可以使用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)
}
}
这是如何应该告诉我,如果按下与否后退按钮? –