如何取消一个UIWebView?
我以模态方式呈现一个 UIViewController
,并使用 UIWebView
作为其视图。当用户点击取消按钮时,如何关闭 UIWebView
?
我的一个想法是将取消按钮链接到 http://cancel ,然后检查
- (void)webViewDidStartLoad:(UIWebView *)webView
If webView.request.URL.host isEqualToString: @"cancel"
,然后关闭视图控制器。
主机中是否必须有一个点,例如“cancel.com”?
I'm modally presenting a UIViewController
with a UIWebView
as its view. How do I dismiss the UIWebView
when the user hits a cancel button on it?
One idea I have is to have the cancel button link to http://cancel and then check in
- (void)webViewDidStartLoad:(UIWebView *)webView
If webView.request.URL.host isEqualToString:@"cancel"
, then dismiss the view controller.
Does the host have to have a dot in it, e.g., "cancel.com"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你走在正确的道路上,但你的方法略有偏差。您不需要也不希望这是一个 HTTP URL。将您的 URL 设置为
取消:
。然后在 Web 视图委托中实现
webView:shouldStartLoadWithRequest:navigationType:
。像这样的东西(未经测试):You're on the right path, but you're approach is slightly off. You don't need or want this to be an HTTP URL. Make your URL
cancel:
.Then implement
webView:shouldStartLoadWithRequest:navigationType:
in your web view delegate. Something like this (untested):目前尚不完全清楚您是想停止在 Web 视图中加载还是只是关闭包含它的模态视图控制器。
停止加载:
关闭视图控制器:
在释放 Web 视图之前,不要忘记将其
delegate
设置为 nil。It's not entirely clear if you want to stop loading in a web view or just dismiss the modal view controller that's containing it.
To stop loading:
To dismiss the view controller:
Don't forget to set the web view's
delegate
to nil before you release it.