Reusing UIWebView

I want to use UIWebview in different view controllers, but I do not want these view controllers to reload the web page, otherwise I want UIWebview to load the page once and use it anywhere. I want to create a web view and load a web page in one way. My question is: is this possible or advisable? Many thanks.

+3
source share
1 answer

What type of your html is for presentation? Is this static HTML content or a dynamic URL?

For static HTML content

I suggest you create your preferred HTML file and upload it directly.

NSString *htmlContent = @"Your Static HTML Code";
NSData *htmlData = [htmlContent dataUsingEncoding:NSUTF8StringEncoding];

if (htmlData) {
    NSString *_path = [[NSBundle mainBundle] bundlePath];
    NSURL *_baseURL = [NSURL fileURLWithPath:_path];
    [self.BottomWebView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:_baseURL];
} 

For a dynamic HTML content base in a URL source

, NSData, . , , ViewController, UIWebview .

, !

0

All Articles