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: 来调用原生方法。

你可能感兴趣的:(UIWebViewDelegate (Objective-C)官方文档翻译)