<! DOCTYPE html>
Viewdidload Code:
NSString *filepath = [[NSBundle mainbundle]pathforresource:@ "book" oftype:@ "html"]; NSString *htmlstring = [NSString stringwithcontentsoffile:filepath encoding:nsutf8stringencoding Error:nil]; [Self.webview loadhtmlstring:htmlstring Baseurl:[nsurl Urlwithstring:filepath];
③ loading the local PDF file, Viewdidload code:
Nsurl *url = [[NSBundle mainbundle]urlforresource:@ "Book.pdf" withextension:nil]; Nsurlrequest *request = [Nsurlrequest requestwithurl:url]; [Self.webview Loadrequest:request];
The second way to load a PDF:
NSString *path = [[NSBundle mainbundle]pathforresource:@ "Book.pdf" oftype:nil]; Loads the data in binary form nsdata *data = [NSData Datawithcontentsoffile:path]; [Self.webview loaddata:data mimetype:@ "application/pdf" textencodingname:@ "UTF-8" baseurl:nil];
④ loading the local TXT file, the Viewdidload code is as follows:
Load txt nsurl *url = [[NSBundle mainbundle]urlforresource:@ "Book.txt" withextension:nil]; Set URL [Self.webview loadrequest:[nsurlrequest Requestwithurl:url];
⑤ load the Word,viewdidload code as follows:
Load Word nsurl *url = [[NSBundle mainbundle]urlforresource:@ "Book.docx" withextension:nil]; Set load URL [Self.webview loadrequest:[nsurlrequest Requestwithurl:url];
⑥ load the network data, the Jump button event is implemented as follows:
Nsurlrequest *request =[nsurlrequest Requestwithurl:[nsurl URLWithString:self.urlText.text]]; [Self.webview Loadrequest:request];
⑦ set up delegates to process data at different stages, Implement Uiwebviewdelegate, set itself as the delegate object;
[Self.webview setdelegate:self];
Three common methods:
Load Start-(void) Webviewdidstartload: (UIWebView *) webview{ NSLog (@ "method call at the beginning of Load");} Load complete-(void) Webviewdidfinishload: (UIWebView *) webview{ NSLog (@ "Computer method call when loading is complete");} Load Error-(void) WebView: (UIWebView *) WebView didfailloadwitherror: (Nserror *) error{ NSLog (@ "Call to load Error");}
iOS development-uiwebview loading local and network data