I’ve written a simple RSSReader with UITableView. I can make a specified feed display by implementing UITableDataSource in my ViewController class. However, I’m trying to display a feed that is entered into a text box. I’ve used NSLogs to debug, and the entered feed is properly parsed upon button press. However, upon [[self tableOfFeeds] reload] the view is not updated.
- (void)viewDidLoad
{
[super viewDidLoad];
[self setNf: [[NewsFeed alloc] init]];
if ([textFieldUserInput.text length] == 0)
link = @"http://afeedurl.com/feed.rss";
[self.nf setFeedUrl:[NSURL URLWithString:link]];
[self.nf retrieveFromInternet];
for (id newsItem in [self.nf newsStories]){ // Debug
NSDictionary * d = (NSDictionary *) newsItem;
NSLog(@"Title: %@ \n %@", [d objectForKey:@"title"], [d objectForKey:@"description"]);
}
[[self tableOfFeeds] setDataSource:self];
[[self tableOfFeeds] setRowHeight:70.0];
[[self tableOfFeeds] reloadData];
}
And here’s the action that changes the feed.
- (IBAction)refreshFeed:(id)sender {
NSString * ui = self.textFieldUserInput.text;
if ([ui length] == 0) // If text field is blank, then reload the old feed from internet.
[[self tableOfFeeds] reloadData];
else {
[self.nf setFeedUrl: [NSURL URLWithString:ui]];
[self.nf retrieveFromInternet];
[[self tableOfFeeds] setDataSource: self];
[[self tableOfFeeds] reloadData];
for (id newsItem in [self.nf newsStories]){ // Debug
NSDictionary * d = (NSDictionary *) newsItem;
NSLog(@"Title: %@ \n %@", [d objectForKey:@"title"], [d objectForKey:@"description"]);
}
}
}
The above code in the question seems to be valid. I traced the issue to this method.
The part that declares the NSMutable Dictionary and sets the cell text needs to be out of the if statement.
I think this works because most of the cells I’d like to change already contain data, and therefore alloc/init doesn’t need to be called.