2014-02-21 15 views
4

我有一個tableView與一些部分,其中都有一個頁腳,然後我有一個TableViewFooter Tableview本身。爲什麼我得到一個assert錯誤當試圖刪除一個tableview中的一段ios

如果我向下滾動到我的tableview的底部,並在最後一節以上的任何部分刪除最後一項(因此總共刪去該條)(倒數第二及以上)它給了我這個錯誤

2014-02-21 13:19:55.066 xxxx[5436:60b] *** Assertion failure in -[UIViewAnimation initWithView:indexPath:endRect:endAlpha:startFraction:endFraction:curve:animateFromCurrentPosition:shouldDeleteAfterAnimation:editing:], /SourceCache/UIKit/UIKit-2903.23/UITableViewSupport.m:2661 
Uncaught exception: Cell animation stop fraction must be greater than start fraction 

在endUpdates

這是我的代碼

[self.tableView beginUpdates]; 
    NSIndexPath *indexPath = [self.tableView indexPathForCell:cell]; 
    if(indexPath != nil){ 
     TableSection * sec = [self.sections objectAtIndex:indexPath.section]; 
     NSMutableDictionary *dic =[sec.items objectAtIndex:indexPath.row]; 

     Product* product = [dic valueForKey:PRODUCT]; 


     //removing the item in the section 
     [sec.items removeObject:dic]; 

     //deleting item from products 
     NSMutableArray *temp = [NSMutableArray array]; 
     for (Product *p in self.dataCon.listPersister.products) { 
      if ([p.product.objId isEqualToString: product.product.objId]) { 
       [temp addObject:p]; 
      } 
     } 

     for (Product *p in temp) { 
      [self.dataCon.listPersister.products removeObject:p]; 
     } 


     //if it was the last object in section, delete the section else just delete the single row 

     if(sec.items.count == 0) 
     { 


      [self.sections removeObject:sec]; 
      [self.footers removeObjectAtIndex:indexPath.section]; 
      [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationFade]; 

     } else 
     { 

      [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
      USFooterView *footer = [self.footers objectAtIndex:indexPath.section]; 
      footer.totalLabel.text = [self.dataCon.listPersister getTotalForShopId:sec.title]; 
      self.footerView.totalLabel.text = [self.dataCon.listPersister getTotalForAllProducts]; 
     } 

    } 


    [self.tableView endUpdates]; 

我有同樣的代碼前面,只是無需頁腳我的tableView和桌子部分,在那裏它瓦特所以我認爲他們可能會成爲問題,但我不完全確定這是它行事的原因。

我已經看到了這個帖子

UITableView tableFooterView may cause crash?

而且它鏈接到職位,但沒有幫助我。

任何幫助表示讚賞:)

+1

你試過這個:http://stackoverflow.com/a/19861743/1179863? –

+0

我剛剛嘗試了一些我以前沒有嘗試過的建議,但是我之前已經看到過這個帖子,但沒有一個答案可以解決我的問題,不過謝謝:) – Hafax

回答

1

我發現了一個「修復」,但我避免使用sectionFooter,因爲它似乎被竊聽。

我在每節結束時創建一個額外的電池,使用相同的設置我之前爲我的頁腳視圖,並作出最後的細胞與

-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    TableSection * sec = [self.sections objectAtIndex:indexPath.section]; 
    if (sec.items.count != indexPath.row) { 
     return YES; 
    } else 
     return NO; 
} 




- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 

     return [sec.items count] +1 ; 

} 


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


TableSection * sec = [self.sections objectAtIndex:indexPath.section]; 

if (indexPath.row != sec.items.count) { 
    //use normal type of cell 


    return cell; 
} else{ 
    //use footer type of cell 

    return cell; 
} 

} 

所以最後一個單元格模仿不可編輯「頁腳「,但它並不卡住框架的底部,但我必須忍受這一點。它比崩潰更好。

1

else語句從表視圖中刪除行:

[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 

而不是從數據源。從你用作數據源的數組中刪除行,它應該起作用。

+1

我正在從2個循環的數據源中刪除項目。首先我找到匹配的產品。第二個循環我從數據源中刪除它們。我在這裏刪除行的原因是因爲如果我完全刪除該部分,我不需要刪除該行。我試着總是刪除行,但是這並沒有改變除動畫之外的東西看起來有點奇怪,因爲它試圖單獨刪除部分和行。 – Hafax

+0

您確定只從該循環中刪除了一個對象,它與您用於從tableview中刪除對象的indexPath完全在同一位置?你如果indexPath!= nil,然後在循環中從數據源中刪除對象,爲什麼不刪除該indexPath上的對象庫。我相信你從數組中刪除的對象與你從tableview中刪除的對象和應用程序崩潰不匹配? – Greg

+0

你說的是一個不同的錯誤。你得到這個代替 'NSInternalInconsistencyException',原因:'無效的更新:在第1節中的行數無效。更新後(8)的現有節中包含的行數必須等於該節中包含的行數(9)中加上或減去插入或刪除的行數(插入0,刪除0),加上或減去移入或移出該部分的行數(0移入,0移入出)。」 而這不是問題在這裏。 – Hafax

0

嘗試使用UITableViewRowAnimationLeft或UITableViewRowAnimationRight作爲刪除行動畫(deleteRowsAtIndexPaths:withRowAnimation :)。

它使用UITableViewRowAnimationAutomatic時會崩潰,但不會與其他兩個。我還沒有嘗試過所有這些,但它似乎是某些選項的動畫代碼的錯誤。

相關問題