2014-01-16 17 views
0

數量無效我有一個問題:NSInternalInconsistencyException '理由是:' 無效的更新:部分

- (void)scrollViewDidScroll:(UIScrollView *)scrollView { 
float reload_distance = 15; 
if(y > h + reload_distance) 
{ 
    if(newNumberOfItemsToDisplay <= [self.arrPodsCanal count]) 
    { 

     for (i=numberOfItemsToDisplay; i<newNumberOfItemsToDisplay; i++) 
      [indexPaths addObject:[NSIndexPath indexPathForRow:i inSection:0]]; 

     numberOfItemsToDisplay = newNumberOfItemsToDisplay; 

     [self.myTable beginUpdates]; 

     [self.myTable insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationMiddle]; 
     if (numberOfItemsToDisplay == totalNumberOfItems) 
       [self.myTable deleteSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationFade]; 

     [self.myTable endUpdates]; 
    } 
} 
} 

,最後的程序,以更新的UITableView我得到這個錯誤:

*終止應用程序由於未捕獲異常'NSInternalInconsistencyException',原因:'嘗試刪除第1部分,但更新前只有1個部分'

問題是當newNumberOfItemsToDisplay == [self .arrPodsCanal計數]認爲

+1

您正在試圖刪除部分1不存在。只有第0部分存在。 –

回答

0

變化:

[self.myTable deleteSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationFade]; 

要:

[self.myTable deleteSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationFade]; 
+0

與「0」我得到此錯誤:***終止應用程序,由於未捕獲的異常'NSInternalInconsistencyException',原因:'無效的更新:在部分0中的行數無效。更新後的現有節中包含的行數50)必須等於更新(1)之前該部分中包含的行數,加上或減去從該部分插入或刪除的行數(插入5個,刪除0個),加上或減去移動的行數進入或退出該部分(0移入,0移出)。' – eugui

+0

所以,現在你必須從numberOfRowsInSection返回適當的值,並返回0.它看起來像一些行也插入 –

+0

我的numberOfRowsInSection: { if(section == 0) return numberOfItemsToDisplay; else return 1; } – eugui

相關問題