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