Load HTML NSString into a UIWebView?

I am assuming that webData is an instance variable on your class. I think your problem is that you are not setting webData to the data you are getting from the NSURLConnection Try something like this.

I am assuming that webData is an instance variable on your class. I think your problem is that you are not setting webData to the data you are getting from the NSURLConnection. Try something like this: - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { webData appendData:data; } If that doesn't do the trick try adding an NSLog() after the NSString *html = NSString alloc... line, like so: NSLog(@"HTML: %@", html); That will tell you whether you are getting HTML or not and whether the problem is with your NSURLConnection code or your UIWebView IBOutlet.

Sorry for not writing that in my question but I have logged the NSString as you described and I get the source of the webpage. I have succeeded to load some another webpage now with my code but some pages won't load. It looks like it only supports "pure" html like pinball.org/rules and not database html like pinballhighscores.org/highscores.php?fil... – ehenrik Oct 27 '10 at 21:15 HTML is HTML.It does not matter whether the HTML was a static .

Html file or whether it was generated from database records. If you know that you have valid HTML, the next thing to check would be the webview. If you try webView loadRequest:NSURLRequest requestWithURL:NSURL URLWithString:@"http://www.google.com", does it work?

– MattLeff Oct 27 '10 at 23:46 I have noticed that it is able to load some webpages but some others not. In the cases that is not working I have noticed that the NSString returns null in connectionDidFinnishLoading, but if I print the data in the didReceiveResponse I get some data, but the last packages arrive as null (differs between 2 - 10 packets). – ehenrik Oct 28 '10 at 7:21.

You are mixing two ways of performing connection - synchronous and asynchronous too. If the asynchronous finishes before the synchronous, you reinitialize webData to empty string. So even if synchronous populated webData it would be cleared.

// you create asynchronous connection which starts downloading in background immediately NSURLConnection *theConnection = NSURLConnection alloc initWithRequest:theRequest delegate:self; // you create another synchronous connection which will block until the URL is downloaded NSURLConnection sendSynchronousRequest:theRequest returningResponse: &responseHeader error: nil; // assuming your theRequest is valid, theConnection is always non-nil, so this is always TRUE if (theConnection) { // you reset content of webData, so if your synchronous connection has downloaded something, you throw it away here webData = NSMutableData data retain; } else ... Try to remove unnecessary/buggy call to sendSynchronousRequest:returningResponse:error: and it might work. Anyway - where do you populate webData with data? You did implement connection:didReceiveData: and append what comes into webData, right?

If you didn't - well, that's the problem you are seeing.

I have populated webData just like you described sorry for not mentioning it from the start. Have updated my question. Seems like some pages can be loaded and other not – ehenrik Oct 27 '10 at 21:17 Well, I was hoping you did implement that method, but the real problem I descried at the beginning of my answer.

Looks like you didn't read carefully, so I added the code with comments to the answer now. – Michal Oct 28 '10 at 5:06 I have used to get some random crashes that pointed to some mistake with webData since I did the changes that you talked about these crashes have stopped. Thanks a bunch!

But however the first problem I had still resist. I have noticed that it is able to load some webpages but some others not. In the case that is not working I have noticed that the NSString returns null connectionDidFinnishLoading, but if I print the data in the didReceiveResponse I get some data, but the last packages arrive as null (differs between 2 - 10 packets).

– ehenrik Oct 28 '10 at 7:20.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions