Reputation: 109
I try to load a URL(in string format) to a UIWebView, but instead of showing the webpage, it shows the URL. Here's my code:
URL = @"www.Google.com"
NSString *path = [[NSBundle mainBundle] bundlePath];
baseURL = [NSURL fileURLWithPath:path];
[webView clearsContextBeforeDrawing];
[webView loadHTMLString:URL baseURL:baseURL];
[webView setNeedsLayout];
Upvotes: 0
Views: 517
Reputation: 2364
You have loaded the content of the UIWebView with the string 'www.Google.com' not the content from that address. loadHTMLString will load HTML content from a string.
You need to use loadRequest.
Upvotes: 1
Reputation: 3200
Use loadRequest
instead for www.Google.com
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"www.google.com"]];
[webView loadRequest:request];
Upvotes: 0
Reputation: 44633
loadHTMLString:baseURL:
takes the html page content as input and not just URL in string form. It treats www.Google.com
as a html string and it gets shown. You will have to do,
NSString * htmlString = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://www.google.com"] encoding:NSUTF8StringEncoding error:nil];
[webView loadHTMLString:htmlString baseURL:nil];
Upvotes: 1