Introduction to the properties of UIWebview and the properties of UIWebview
/* ViewController. h file */
# Import <UIKit/UIKit. h>
@ Interface ViewController: UIViewController
@ End
/* ViewController. m file */
# Import "ViewController. h"
@ Interface ViewController (){
IBOutlet UIWebView * _ webView;
}
@ End
@ Implementation ViewController
-(Void) viewDidLoad {// Load
[Super viewDidLoad];
/*
Three Data Loading Methods
-(Void) loadRequest :( NSURLRequest *) request;
-(Void) loadHTMLString :( NSString *) string baseURL :( NSURL *) baseURL;
-(Void) loadData :( NSData *) data MIMEType :( NSString *) MIMEType textEncodingName :( NSString *) textEncodingName baseURL :( NSURL *) baseURL;
*/
[Self loadData1]; // method 1 for loading data
[Self loadData2]; // method 2 for loading data
[Self loadData3]; // method 3 for loading data
}
# Pragma mark-URL data loading (Network Data)
-(Void) loadData1 {
NSURL * data = [NSURL URLWithString: @ "http://v.youku.com/v_show/id_XMTQzNTM1NzA2OA==_ev_1.html? From = y1.3-idx-uhome-1519-20887.205805-205902.1-1 "];
NSURLRequest * data1 = [NSURLRequest requestWithURL: data]; // Request
[_ WebView loadRequest: data1];
}
# Pragma mark-HTML local data loading
-(Void) loadData2 {
// Read path (from the local path)
NSString * path = [[NSBundle mainBundle] pathForResource: @ "news" ofType: @ "html"];
// Extract the content of this file based on the path (the content is in string format)
NSString * dataString = [[NSString alloc] initWithContentsOfFile: path encoding: NSUTF8StringEncoding error: nil]; // Content // encoding
// Add data to html
NSString * html = [NSString stringWithFormat: dataString, @ "111", @ "222", @ "333", @ "444", @ "555"];
// Load data
WebView loadHTMLString: html baseURL: nil];
}
# Pragma mark-HTML Network Data Loading
-(Void) loadData3 {
// Obtain the path
NSString * path = [[NSBundle mainBundle] pathForResource: @ "Baidu" ofType: @ "html"];
/*
NSData: When we need to write some information to a file or send it to the network, we need to convert the data, turns to a pure 0-and 1-hour stream (the NSData type is Data Stream)
*/
// Extract data based on the path (the data format is Data Stream)
NSData * data = [NSData dataWithContentsOfFile: path];
// Load html data on the network
[_ WebView loadData: data MIMEType: nil textEncodingName: nil baseURL: nil];
}
# Pragma mark-UIWebViewDelegate (proxy method)
// Called when loading data
-(BOOL) webView :( UIWebView *) webView shouldStartLoadWithRequest :( NSURLRequest *) request navigationType :( UIWebViewNavigationType) navigationType {
Return YES;
}
// Called when loading data
-(Void) webViewDidStartLoad :( UIWebView *) webView {
}
// Called when data loading ends
-(Void) webViewDidFinishLoad :( UIWebView *) webView {
}
// Call when an error occurs during data loading
-(Void) webView :( UIWebView *) webView didFailLoadWithError :( NSError *) error {
}