Why am I getting an error when trying to delete a partition in iOS

I have a tableView with some sections, all of which have a footer, and then I have a tableViewFooter in the TableView itself.

If I scroll down the bottom of the table and delete the last element (so I completely delete the section) in any sections above the last section (second and last), it gives me this error

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

at endUpdates

this is my code

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

I had the same code before, just without my tabular and tabular sections having footers where it worked, so I think this might be a problem, but I'm not quite sure what the reason it works.

I saw this message

Can a UITableView tableFooterView crash?

And the message he refers to, but that did not help me.

Any help is appreciated :)

+4
3

"", 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

Try using UITableViewRowAnimationLeft or UITableViewRowAnimationRight as an animation of a delete line (deleteRowsAtIndexPaths: withRowAnimation :).

It crashed for me when using the UITableViewRowAnimationAutomatic, but not with the other two. I have not tried them all, but it seems to be a bug with the animation code for some parameters.

0
source

Source: https://habr.com/ru/post/1528092/


All Articles