Problem with RowAnimation

Hey guys. i have a problem with animating deletes and inserts on a UITableView. The Fact ist, that i have different cellheights, some 44.0 some 135.0 now. i have uitableviewstylegrouped with different sections. the first row of each sections is a grouping row. on click i remove all rows of this section except the grouping row. but that animation looks weird, when animating (UITableViewRowAnimationTop) the 135px height cell. i tried to set self.tableview.cellheight to 135 and commented out the tableView:cellHeightForIndexPath-Method. And the Animation works fine. Or i set every cellheight to 135 in tableView:cellHeightForIndexPath-Method.

It looks like the animation process checks the height of the first row in the sections an takes that height of the cell for all following cells to animate.

Somebody an idea?


- (void) showhideGroup:(int)group
{   
    NSMutableArray *indexPaths = [[NSMutableArray alloc] init];

    MCGroup *handleGroup = [groups objectAtIndex:group];
    NSMutableArray *groupRows = [visibleGroupData objectForKey:handleGroup.title];

    [self.tableView beginUpdates];

    if (!handleGroup.hidden) {
        int row = 0;
        for(MobileFieldMapping *field in groupRows)
        {
            if (![field.datatype matchesInsensitive:GROUPING_CELL]) 
            {
                NSIndexPath *path = [NSIndexPath indexPathForRow:row inSection:group];
                [indexPaths addObject:path];
            }
            row++;
        }

        row = 0;
        for(NSIndexPath *index in indexPaths)
        {
            [groupRows removeObjectAtIndex:index.row-row];
            row++;
        }
        [self.tableView deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationTop];
        handleGroup.hidden=YES;
    }
    else 
    {
        NSMutableArray *allGroupRows = [groupData objectForKey:handleGroup.title];

        int row = 0;
        for (MobileFieldMapping *field in allGroupRows) 
        {
            if (![groupRows containsObject:field]) 
            {
                NSIndexPath *path = [NSIndexPath indexPathForRow:row inSection:group];
                [indexPaths addObject:path];
                [groupRows insertObject:field atIndex:row];
            }
            row++;
        }

        [self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationTop];
        handleGroup.hidden=NO;
    }
    [self.tableView endUpdates];


    [indexPaths release];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{   
    UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];

    if ([cell isKindOfClass:[FormCell class]]) 
    {
        return [(FormCell*)cell height];
    }

    return 44.0;
}
6
задан kaelum 5 November 2010 в 08:32
поделиться