簡體   English   中英

為什么我在嘗試刪除tableview ios中的部分時出現斷言錯誤

[英]Why am I getting an assert Error When trying to Delete a section in a tableview ios

我有一個tableView和一些部分,都有一個頁腳,然后我在Tableview本身有一個tableViewFooter。

如果我向下滾動到我的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可能導致崩潰?

和它鏈接的帖子,但這對我沒有幫助。

任何幫助表示贊賞:)

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

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

但不是來自數據源。 從數組中刪除用作數據源的行,它應該可以工作。

我發現了一個“修復”,但我避免使用sectionFooter,因為這似乎有問題。

我在每個部分的末尾創建了一個額外的單元格,使用了我之前為我的頁腳View設置的相同設置,並使最后一個單元格不可編輯

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

}

所以最后一個單元格模仿了一個“頁腳”,但它沒有粘在框架的底部,但我必須忍受它。 它比崩潰更好。

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM