【发布时间】:2011-05-04 22:28:53
【问题描述】:
我在 UITableView 上为删除和插入设置动画时遇到了问题。事实是,我有不同的单元格高度,现在一些 44.0 一些 135.0。我将 uitableviewstyle 与不同的部分分组。每个部分的第一行是一个分组行。单击时,我删除了除分组行之外的该部分的所有行。但是,当动画(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;
}
【问题讨论】:
-
你应该发布表格视图委托源代码。
-
好吧,没有人知道......似乎是这样
-
我已经完成了这项工作,所以我认为这是您代码中的错误。您需要发布完整的代码,或者(更好地)制作一个较小的问题示例。此外,您需要更具体地描述它“看起来很奇怪”的确切方式 - 没有人可以帮助您解决这种模糊。
-
我也遇到了同样的问题,你找到解决办法了吗?
标签: iphone animation height row cell