iPhone RSS 阅读器应用程序中的刷新问题
我正在研究我在网站上找到的这个教程。它是一个 RSS 源应用程序。链接如下: RSS 教程< /a>
我已经在我的应用程序中使用了 RSS Feed。我很好奇,没有使用普通的刷新按钮,而是选择了下拉刷新。 PullDownRefresh 教程
我在 RSS feed 中实现了这一点。一切看起来都不错并且可以工作,但只是不令人耳目一新。因此,我尝试添加一些代码,以便在拉下表格视图时使其刷新。
我输入的代码是:
- (void)reloadTableViewDataSource {
//should be calling your tableviews data source model to reload.
//put here just for demo.
[self performSelector:@selector(refresh)];
_reloading = YES;
[self.tableView reloadData];
}
但这会重复提要。
在此之前我尝试使用 self.tableView.dataSource = nil;
清除数据源,但添加此操作会使其崩溃:
`- (void)requestFinished:(ASIHTTPRequest *)request {
[_queue addOperationWithBlock:^{
NSError *error;
GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData:[request responseData]
options:0 error:&error];
if (doc == nil) {
NSLog(@"Failed to parse %@", request.url);
} else {
NSMutableArray *entries = [NSMutableArray array];
[self parseFeed:doc.rootElement entries:entries];
NSSortDescriptor *itemSort = [[NSSortDescriptor alloc] initWithKey:@"articleDate" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:itemSort,nil];
[entries sortUsingDescriptors:sortDescriptors];
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
for (RSSEntry *entry in entries) {
int insertIdx = [_allEntries indexForInsertingObject:entry sortedUsingBlock:^(id a, id b) {
RSSEntry *entry1 = (RSSEntry *) a;
RSSEntry *entry2 = (RSSEntry *) b;
return [entry1.articleDate compare:entry2.articleDate];
}];
[_allEntries insertObject:entry atIndex:insertIdx];
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:insertIdx inSection:0]] //Thread 1: Program received signal: "SIGABRT".
withRowAnimation:UITableViewRowAnimationRight];
}
}];
}
}];
}`
输出窗口显示此信息:
由于未捕获的异常而终止应用程序 'NSInternalInconsistencyException',原因:'无效更新:无效 第 0 节中的行数。包含在第 0 节中的行数 更新后的现有部分 (0) 必须等于 更新之前该部分中包含的行 (0),加上或减去 从该部分插入或删除的行数(1 已插入, 0 已删除)。'
有什么想法吗?
I am playing around with this tutorial I found on a website. It is an RSS Feed application. Here's the link: RSS Tutorial
I have got the RSS Feed working in my application. I got curious and instead of having a normal refresh button, I opted for a pull down refresh. PullDownRefresh Tutorial
I implemented into the RSS feed. All looks good and working but just not refreshing. So I tried adding some code in in order to make it refresh when I pull the tableview down.
The code I put is:
- (void)reloadTableViewDataSource {
//should be calling your tableviews data source model to reload.
//put here just for demo.
[self performSelector:@selector(refresh)];
_reloading = YES;
[self.tableView reloadData];
}
But this duplicates the feeds.
I tried to clear my datasource prior to this with self.tableView.dataSource = nil;
but adding this crashes it here:
`- (void)requestFinished:(ASIHTTPRequest *)request {
[_queue addOperationWithBlock:^{
NSError *error;
GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData:[request responseData]
options:0 error:&error];
if (doc == nil) {
NSLog(@"Failed to parse %@", request.url);
} else {
NSMutableArray *entries = [NSMutableArray array];
[self parseFeed:doc.rootElement entries:entries];
NSSortDescriptor *itemSort = [[NSSortDescriptor alloc] initWithKey:@"articleDate" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:itemSort,nil];
[entries sortUsingDescriptors:sortDescriptors];
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
for (RSSEntry *entry in entries) {
int insertIdx = [_allEntries indexForInsertingObject:entry sortedUsingBlock:^(id a, id b) {
RSSEntry *entry1 = (RSSEntry *) a;
RSSEntry *entry2 = (RSSEntry *) b;
return [entry1.articleDate compare:entry2.articleDate];
}];
[_allEntries insertObject:entry atIndex:insertIdx];
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:insertIdx inSection:0]] //Thread 1: Program received signal: "SIGABRT".
withRowAnimation:UITableViewRowAnimationRight];
}
}];
}
}];
}`
The output window says this:
Terminating app due to uncaught exception
'NSInternalInconsistencyException', reason: 'Invalid update: invalid
number of rows in section 0. The number of rows contained in an
existing section after the update (0) must be equal to the number of
rows contained in that section before the update (0), plus or minus
the number of rows inserted or deleted from that section (1 inserted,
0 deleted).'
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)