views:

1026

answers:

2

I have an RSS feed that gets arranged in a UITableView which lets the user select a story that loads in a UIWebView. However, I'd like to stop using the UIWebView and just use a UITextView or UILabel.

This png is what I am trying to do (just display the various text aspects of a news story):

alt text

I have tried using:

NSString *myText = [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.textContent"];

and assigning the string to a UILabel but it doesn't work from where I am implementing it in webViewDidFinishLoad (--is that not the proper place?). I get a blank textView and normal webView.

If I overlay a UITextView on top of a UIWebView on its own (that is, a webView that just loads one page), the code posted above works displays the text fine. The problem arises when I try to process the RSS feed .

I've been stuck wondering why this doesn't work as it should for a few days now. If you have a better, more efficient way of doing it then placing the code in webViewDidFinishLoad, please let me know! Does it go in my didSelectRowAtIndexPath?

Thank you very much in advance!

A: 

If the NSString you want to display is not empty, try to do something like this in the webViewDidFinishLoad method:

[yourUILabel performSelectorOnMainThread:@selector(setText:) withObject:[NSString stringWithFormat:@"bla bla %@", @"more bla"] waitUntilDone:YES];

The main thread of an iphone app is responsible for drawing components, that is why your label doesn't show your text.

You could also try setting setNeedsDisplay: to true

Also, the UILabel will not preserve the HTML format. It will display it as just text.

SorinA.
Hi, Sorin, thanks for the reply.I implemented that in webViewDidFinishLoad, but I suppose since I am not accustom to working with NSStrings, I am screwing it up. What is the format of the string (i.e. what goes after the stringWithFormat?)For example, this is a sample RSS feed:http://tinyurl.com/rssexampleThank you for helping me!
ArgMan
Like TechZen said and I pointed you should first see if the NSString that you want to display is not empy.about the NSString class you can read here: http://developer.apple.com/iphone/library/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html .NSString *myString = [NSString stringWithFormat:@"%@", parameter];where parameter can be another NSString object or @"i have a cat".the %@ after stringWithFormat represents the placeholder for the parameter content, in this case a NSString. For float you can use %f if i recall correctly, %d = integers and so on
SorinA.
i looked over the xml. there you have a title, description, url for the news, thumbnail url. First thing you want to do is to download asynchronous the webpage found at the address specified in the link tag of the xml. And after that try to parse it somehow... the UILabel will display all the text including html tags if you will show the text directly without any parsing.
SorinA.
+1  A: 

I think the you should first log the string returned by :

NSString *myText = [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.textContent"];

... in the case of the RSS feed to make sure that you are getting something back. It's possible the RSS page doesn't have the same javascript components and that it returns an empty string.

Once you've confirmed that, then it becomes a simple matter of getting it to display properly in the text view.

TechZen