繁体   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