In my web browser, I am trying to load a UIWebView
with NSData
obtained from a NSURLConnection
. When I try to load it into the UIWebView
, instead of the site, it comes up with the HTML plain text.
Here is my code:
in viewDidLoad:
NSURLRequest *request = [NSURLRequest requestWithURL: [NSURL URLWithString:@"http://www.msn.com"]];
[NSURLConnection connectionWithRequest: request delegate:self];
later in the code:
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
webdata = [NSMutableData dataWithData: data];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[webview loadData:webdata MIMEType: @"text/html" textEncodingName: @"UTF-8" baseURL:nil];
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…