One: There are three ways to load data UIWebView:
1:-(void) Loadrequest: (Nsurlrequest *) request
NSString * Path = [[NSBundle mainbundle] Pathforresource:@ "demofolder" ofType:@ " HTML " ]; *url = [Nsurl Urlwithstring:path]; [Self.webview1 loadrequest:[nsurlrequest Requestwithurl:url];
Where the URL can be remote or local.
2:-(void) loadhtmlstring: (NSString *) string BaseURL: (Nsurl *) BaseURL
NSString * Path = [[NSBundle mainbundle] Pathforresource:@ "demofolder" ofType:@ " HTML " ]; [Self.webview1 loadhtmlstring:htmlstring Baseurl:[nsurl Urlwithstring:path];
3:-(void) LoadData: (NSData *) data MIMEType: (NSString *) MIMEType textencodingname: (NSString *) Textencodingname BaseURL :(nsurl*) BaseURL
Data is a file, MimeType is a file type, Textencodingname is an encoding type, and BaseURL is a material resource path
NSString * Path = [[NSBundle mainbundle] Pathforresource:@ " demofolder oftype:@" html * htmlstring = [NSString Stringwithcontentsoffile:path encoding: Nsutf8stringencoding Error:nil]; NSData * htmldata = [htmlstring datausingencoding:nsutf8stringencoding]; [Self.webview1 loaddata:htmldata MIMEType: @ " text/html " textencodingname:@" utf-8 Baseurl:[nsurl Urlwithstring:path]];
Two: BaseURL is the path that you set up to load the resources needed for HTML.
Because the front-end specifications are CSS files and JavaScript files, as well as the picture files are grouped into a single door folder, so I created three folders: CSS, JavaScript, pic which are stored city.css, alert.js, test22.png
Then pull these files down the bundle and discover whether the Group folder or the Entity folder, Css,js and pictures are not loaded.
Then remove the folder, leaving only the individual files:
This will load up normally. Instead, replace the BaseURL path with the path to the CSS file:
NSString * basestring = [[NSBundle mainbundle] Pathforresource:@ "City" ofType:@ " CSS " ]; * BaseUrl = [Nsurl urlwithstring:basestring];
Files can also be loaded out, JS and pictures display normal.
Do not know if there is no other way to keep the HTML file path, write to the document folder directory? Well, waiting to be tested ...
WebView loading Local HTML CSS JavaScript file path attempt