UIWebViewDelegate (Objective-C)官方文档翻译

继承自NSObject

导入声明:@import UIKit

适用范围:iOS 2.0 及以后

UIWebViewDelegate 协议定义了一些方法, UIWebView 对象的代理(delegate)可以选择性地去实现这些方法,以便介入网页内容(web content)的加载。

重要
在释放一个 UIWebView 实例之前,如果你为其设过代理(delegate)的话,你首先一定要在销毁 UIWebView 实例之前,将这个 UIWebView 的 delegate 属性置为 nil。比如,你可以在销毁 UIWebView 的 dealloc 方法中这样处理。
IMPORTANT
Before releasing an instance of UIWebView for which you have set a delegate, you must first set theUIWebView delegate property to nil before disposing of the UIWebView instance. This can be done, for example, in the dealloc method where you dispose of the UIWebView.

一、职能(Tasks)

加载内容(Loading Content)

- webView:shouldStartLoadWithRequest:navigationType:

Sent before a web view begins loading a frame.

Declaration

- (BOOL)webView:(UIWebView *)webView
shouldStartLoadWithRequest:(NSURLRequest *)request
 navigationType:(UIWebViewNavigationType)navigationType

Parameters

参数 含义
webView The web view that is about to load a new frame.
request The content location.
navigationType The type of user action that started the load request.

Return Value
YES if the web view should begin loading content; otherwise, NO.

Availability
Available in iOS 2.0 and later.


- webViewDidStartLoad:

Sent after a web view starts loading a frame.

Declaration

- (void)webViewDidStartLoad:(UIWebView *)webView

Parameters

参数 含义
webView The web view that has begun loading a new frame.

Availability
Available in iOS 2.0 and later.

See Also
– webView:shouldStartLoadWithRequest:navigationType:
– webViewDidFinishLoad:
– webView:didFailLoadWithError:


- webViewDidFinishLoad:

Sent after a web view finishes loading a frame.

Declaration

- (void)webViewDidFinishLoad:(UIWebView *)*webView*

Parameters

参数 含义
webView The web view has finished loading.

Availability
Available in iOS 2.0 and later.

See Also
– webView:shouldStartLoadWithRequest:navigationType:
– webViewDidStartLoad:
– webView:didFailLoadWithError:


- webView:didFailLoadWithError:

Sent if a web view failed to load a frame.

Declaration

- (void)webView:(UIWebView *)*webView*
didFailLoadWithError:(NSError *)*error*

Parameters

参数 含义
webView The web view that failed to load a frame.
error The error that occurred during loading.

Availability
Available in iOS 2.0 and later.

See Also
– webView:shouldStartLoadWithRequest:navigationType:
– webViewDidStartLoad:
– webViewDidFinishLoad:

二、文档修订记录(Document Revision History)

下表中列出的是文档 UIWebViewDelegate Protocol Reference 的变化。

日期 说明
2011-05-26 Web view delegate methods may be called once per frame in the source document, not once per page.
2008-10-15 添加了关于设置 UIWebView 的 delegate 为 nil 的警告。
2008-09-09 删除了关于“页面比例改变时会通知代理(delegate)”的描述。
2008-03-12 描述协议的新文档,这份协议用于介入网页(web content)加载或者页面比例的改变。

参考(Reference)
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIWebViewDelegate_Protocol/index.html#//apple_ref/occ/intf/UIWebViewDelegate


问题(Question)
1.“ load a frame” 中的 “frame” 指的是什么?与 “page” 有什么区别?
2.当 web view 的代理方法 - webViewDidFinishLoad: 被调用时,图片并没有加载完全,这是为什么?
3.web view 调用 JavaScript 是在什么时机,哪个代理方法?
4.如何通过代理方法 - webView:shouldStartLoadWithRequest:navigationType: 来调用原生方法。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • UIWebView 一、概览(Overview) 1.支持的文件格式(Supported File Formats...
    ShannonChenCHN阅读 1,322评论 0 1
  • IOS之UIWebView的使用 刚接触IOS开发1年多,现在对于 混合式 移动端开发越来越流行,因为开发成本上、...
    学无止境666阅读 45,914评论 5 53
  • OS之UIWebView的使用 刚接触IOS开发1年多,现在对于 混合式 移动端开发越来越流行,因为开发成本上、速...
    知之未道阅读 1,670评论 0 4
  • iOS开发系列--网络开发 概览 大部分应用程序都或多或少会牵扯到网络开发,例如说新浪微博、微信等,这些应用本身可...
    lichengjin阅读 3,721评论 2 7
  • 假如可以一直坐下去,苏菲这样想着,冷不防一颗石子正中湖心,发出听不见的响声,激起不大不小的涟漪,涌起几圈波纹...
    碧水精魄阅读 179评论 0 0