2012-11-06 4 views
1

parsingDidEnd 구문 분석시 tableupdate를 구현 중입니다. 사용자가 테이블 및 스크롤 끝 도달 할 때 ... 구문 분석 호출 할 때 및 구문 분석 할 때 ... UITableView 업데이트 ... 그것은 완벽하게 작동하지만 내가 TableView를 4-5 시간 동안 계속 스크롤하면 오류가 발생합니다 다음과 같이 다음과 같이UITableView 업데이트시 앱이 충돌 함

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]; 
     } 

    }} 

답변

1

numberofRowsinSection 확실히 잘못된 값을 반환합니다 :

섹션 0에있는 행의 수가 올바르지 않음. 행수 업데이트 후 기존 섹션 에 포함 (50) 업데이트 (40), 플러스 마이너스 삽입 행수 이전 섹션 함유 행 수가 같아야 또는 해당 섹션에서 삭제했습니다. (20이 삽입되었습니다., 삭제됨).

40 + 20! = 50

관련 문제