UIWebView How to load data

Source: Internet
Author: User

Declaring a variable of type UIWebView

{

UIWebView *webview;

}

mode one: loadrequest (requires URL loading data mode) For example: (Http://www.letv.com/ptv/vplay/24329094.html?ch=baidu_ald);

Nsurl *url = [Nsurl urlwithstring: @ "url"];

Nsurlrequest *request = [[Nsurlrequest Alloc]initwithurl:url];

Loading data

[WebView Loadrequest:request];

Way Two LoadData (requires the source code of the HTML page)

1. Get the path to the HTML file (save the source code of the Baidu Web page as a baidu.html file)

NSString *path =[[nsbundle mainbundle]pathforresource:@ "Baidu" oftype:@ "html"]

2. Convert the contents of this path into the NSData type

NSData *data = [NSData Datawithcontentsoffile:path];

3. Loading data

[WebView loaddata:data Mimetype:nil Textencodingname:nil Baseurl:nil];

Way Three loadhtmlstring (by loading an HTML string for the variable padding value for this file) for example: (news.html);

1. Get the file where the htmlstring is located

NSString *path =[[NSBundle mainbundle]pathforresource:@ "News" oftype:@ "html"];

2. Convert the contents of a file into a string

NSString *string = [[NSString alloc]initwithcontentsoffile:path encoding:nsutf8stringencoding Error:nil];

3. Send a value to the string you get (create Htmlstring)

UIString *htmlstring = [NSString stringwithformat:string, @ "xxxx", @ "xxxx"];//html files need several values to pass in several values

4. Loading data

[WebView loadhtmlstring:htmlstring Baseurl:nil];

UIWebView How to load data

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.