【问题标题】:Problem with refresh in iPhone RSS reader appiPhone RSS阅读器应用程序中的刷新问题
【发布时间】:2011-10-02 15:48:18
【问题描述】:

我正在玩我在网站上找到的本教程。它是一个 RSS Feed 应用程序。这是链接:RSS Tutorial

我的应用程序中的 RSS 提要正在运行。我很好奇,我没有使用普通的刷新按钮,而是选择了下拉刷新。 PullDownRefresh Tutorial

我在 RSS 提要中实现了。一切看起来都很好,而且工作正常,但并不令人耳目一新。所以我尝试添加一些代码,以便在我拉下 tableview 时让它刷新。

我放的代码是:

- (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 个已删除)。'

有什么想法吗?

【问题讨论】:

    标签: iphone uitableview rss refresh reload


    【解决方案1】:
    - (void)viewDidLoad
    {
    [super viewDidLoad];
    
    self.navigationController.navigationBar.tintColor = [UIColor blackColor];
    self.allEntries = [NSMutableArray array];    
    self.title= NSLocalizedString(@"News feeds", @"Storage");   
    self.queue = [[[NSOperationQueue alloc] init ] autorelease];
    self.feeds = [NSArray arrayWithObjects:
                  @"feed://www.yourfeed.com/feed.xml",
                  nil];    
    
    [self.tableView reloadData];
    
    // Add the right reload button
    UIBarButtonItem *reloadButton = [[UIBarButtonItem alloc] 
                           initWithTitle:NSLocalizedString(@"Refresh")                                            
                           style:UIBarButtonItemStyleBordered 
                           target:self 
                           action:@selector(viewDidLoad)];
    self.navigationItem.rightBarButtonItem = reloadButton;
    self.navigationItem.rightBarButtonItem.style = UIBarButtonItemStyleDone;
    [reloadButton release];
    
    [self refresh];
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-23
      • 2015-08-06
      • 1970-01-01
      • 1970-01-01
      • 2011-06-27
      • 1970-01-01
      • 2011-07-27
      相关资源
      最近更新 更多