我正在 parsingDidEnd 解析上实现 tableupdate。当用户到达表格末尾并滚动时...我调用解析并且解析完成后...UITableView
更新...它工作得很好但是当我连续滚动 TableView 4-5 次时它崩溃并出现如下错误:
2012-11-06 17:19:14.810 MightyGoodDeals[1345:707] *** 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 (50) must be equal to the number of rows contained in that section before the update (40), plus or minus the number of rows inserted or deleted from that section (20 inserted, 0 deleted).
找到我的更新代码如下:
#pragma mark <myLIBXMLParser> Implementation- (void)parserDidEndParsingData:(myLIBXMLParser *)parser {
// self.title = [NSString stringWithFormat:@"%i Patients Records", [objects count]];
//self.navigationItem.rightBarButtonItem.enabled = YES;
self.parser = nil;
NSLog(@"%@",[objects description]);
if ([objects count]==0 ||[[[objects objectAtIndex:0]valueForKey:@"NoData"]isEqualToString:@"0"]) {
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"MightyGoodDeals" message:@"There are no deals to display." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[self removeLoadingView];
}
else {
NSLog(@"in else");
[self removeLoadingView];
NSMutableArray *indexArray=[[NSMutableArray alloc]init];
NSLog(@"%d",[objects count]);
NSLog(@"intSkip: %d",intSkip);
for (int i=intSkip; i<[objects count]; i++)
{
NSLog(@"in for loop");
NSLog(@"%d",i);
NSIndexPath *path=[NSIndexPath indexPathForRow:i inSection:0];
[indexArray addObject:path];
}
[self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView endUpdates];
self.tableView.tableFooterView = nil;
[self.tableView setSeparatorColor:[UIColor blackColor]];
//[self.tableView reloadData];
int value=[[[objects objectAtIndex:[objects count]-1]valueForKey:@"Skip"]intValue];
float remainder = fmod([objects count],value);
int endValue=(int)remainder;
if (endValue==0)
{
syncParse=TRUE;
}
else
{
syncParse=FALSE;
}
}}
- (void)parser:(myLIBXMLParser *)parser didParseObjects:(NSArray *)parsedObjects{ [objects addObjectsFromArray:parsedObjects]; }
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat height = scrollView.frame.size.height;
CGFloat contentYoffset = scrollView.contentOffset.y;
CGFloat distanceFromBottom = scrollView.contentSize.height - contentYoffset;
if(distanceFromBottom < height)
{
NSLog(@"end of the table");
if (syncParse)
{
int value=[[[objects objectAtIndex:[objects count]-1]valueForKey:@"Skip"]intValue];
intSkip=value;
[NSThread detachNewThreadSelector:@selector(StartParsing) toTarget:self withObject:nil];
UIView *loadingViewShow=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 44)];
UIActivityIndicatorView *spinner = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray] autorelease];
[spinner startAnimating];
spinner.frame = CGRectMake(115, 15, 20,20);
[loadingViewShow addSubview:spinner];
UILabel *lbl=[[UILabel alloc]initWithFrame:CGRectMake(140, 0, 160, 44)];
[lbl setText:@"Loading....."];
[lbl setBackgroundColor:[UIColor clearColor]];
[lbl setTextColor:[UIColor grayColor]];
[loadingViewShow addSubview:lbl];
self.tableView.tableFooterView = loadingViewShow;
//[self StartParsing];
}
}}