Introduction to the properties of UIWebview and the properties of UIWebview

Source: Internet
Author: User

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 {

 

 

}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.