1

我嵌入了我的项目EGOTableViewPullRefresh,一切正常并且更新正常,但是当我将视图拉下太多以进行更新时,应用程序崩溃并出现错误:

2012-04-24 19:02:56.670 测试 [3927: f803] * 由于未捕获的异常“NSRangeException”而终止应用程序,原因:“* - [__NSArrayM objectAtIndex:]:空数组的索引 2 超出范围” *第一次抛出调用堆:

一段代码

self.tabBarController = [[[UITabBarController alloc] init] autorelease];
NSMutableArray * viewControllers = [[NSMutableArray alloc] init];


//plist file full path
NSString *urlStr = [[NSString alloc] 
                    initWithFormat:@"http://www.test.com/data.xml?seedVar=%f", 
                    (float)random()/RAND_MAX];
NSURL *url = [NSURL URLWithString:urlStr];
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfURL:url];

  //Get the folder array
NSArray * subscriptionFolders = [dict objectForKey:@"Folders"];

更新

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
        [cell.textLabel setNumberOfLines:2];
        [cell.detailTextLabel setNumberOfLines:3];
        [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
    }

    RSSItem * rssItem = (RSSItem *)[_rssParser.rssItems objectAtIndex:indexPath.row];
    [cell.textLabel setText:rssItem.title];
    [cell.detailTextLabel setText:rssItem.summary];

    return cell;
}

你能帮我解决这个问题吗?

4

1 回答 1

0

我找到了解决方案。当我在reloadTableViewDataSource中调用rssParser时,它崩溃了。当我尝试在dataSourceDidFinishLoadingNewData中调用rssParser时,一切正常而不会崩溃。

- (void)reloadTableViewDataSource{
[super performSelector:@selector(dataSourceDidFinishLoadingNewData) withObject:nil afterDelay:2.0];
}

- (void)dataSourceDidFinishLoadingNewData{
    [_rssParser start];
    [refreshHeaderView setCurrentDate]; 
    [super dataSourceDidFinishLoadingNewData];   
}
于 2012-04-26T11:38:04.317 回答