我用 UITableView 编写了一个简单的 RSSReader。我可以通过在 ViewController 类中实现 UITableDataSource 来显示指定的提要。但是,我正在尝试显示输入到文本框中的提要。我使用 NSLogs 进行调试,输入的提要在按钮按下时被正确解析。但是,在[[self tableOfFeeds] reload]
视图没有更新。
- (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];
}
这是更改提要的操作。
- (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"]);
}
}
}