kae*_*lum 6 iphone height animation row cell
大家好.我有一个问题,在UITableView上动画删除和插入.事实是,我有不同的单元格高度,现在大约44.0有135.0.我有uitableviewstylegrouped与不同的部分.每个部分的第一行是分组行.点击我删除除分组行以外的所有行.但是当动画(UITableViewRowAnimationTop)135px高度单元格时,该动画看起来很奇怪.我试图将self.tableview.cellheight设置为135并注释掉tableView:cellHeightForIndexPath-Method.而动画效果很好.或者我在tableView:cellHeightForIndexPath-Method中将每个cellheight设置为135.
看起来动画过程会检查各个部分中第一行的高度,以获取所有后续单元格的动画高度.
有人有点想法吗?
- (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;
}
Run Code Online (Sandbox Code Playgroud)
一个仍然没有答案的旧问题。我想你很久以前就明白了,但这是我的第一个想法。(我记得我自己也尝试过做这样的事情。)
当UITableView调用时heightForRowAtIndexPath:,这是因为表格正在尝试准备单元格,所以您不能使用单元格返回高度。这可能会导致调用中的无限回归,或者它可能会检测到这一点并放弃或抛出异常,让您独自承担责任。
您必须在不使用单元本身的情况下计算单元高度。
至于单元格高度假设,请尝试对单个单元格调用插入/删除,而不是一次调用一次完成所有操作。在您调用后,仍然会将它们UITableView批量添加到动画中endUpdates。