我在第 4 节中有一个带有可展开行的 UITableView。当展开一行时,其他行需要折叠。我重新加载指定的行并滚动表以将展开的行放在顶部。这是代码:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (indexPath.section == 4)
{
if (indexPath.row == 0)
{
if (hypoExpanded)
{
hypoExpanded = NO;
[self performSelector:@selector(reloadRowWithScrollForIndexPath:) withObject:indexPath afterDelay:kAnimationDelay];
}
else
{
hypoExpanded = YES;
moodExpanded = NO;
activityExpanded = NO;
NSArray *indexArray = [NSArray arrayWithObjects:indexPath, [NSIndexPath indexPathForRow:1 inSection:4], [NSIndexPath indexPathForRow:2 inSection:4], nil];
[self performSelector:@selector(reloadRowWithScrollForIndexArray:) withObject:indexArray afterDelay:kAnimationDelay];
}
... }
}
- (void)reloadRowWithScrollForIndexArray:(NSArray *)indexArray
{
[self.tableView reloadRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:((NSIndexPath *)[indexArray objectAtIndex:0]).row inSection:((NSIndexPath *)[indexArray objectAtIndex:0]).section] atScrollPosition:UITableViewScrollPositionTop animated:YES];
}
- (void)reloadRowWithScrollForIndexPath:(NSIndexPath *)indexPath
{
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section] atScrollPosition:UITableViewScrollPositionTop animated:YES];
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
switch (section)
{
case 1:
return [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bgc-info"]];
break;
case 2:
return [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"in-info"]];
break;
case 3:
return [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bp-info"]];
break;
case 4:
return [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"per-info"]];
break;
}
return nil;
}
有时,随机的部分标题(1、2 或 3)会复制并覆盖属于该部分的单元格。滚动表格以使该部分消失无济于事。当我向后滚动时,重复的标题仍然存在。它只发生在 iOS 6 上。调用 performSelectorOnMainThread: 也没有帮助。此外,无需调用 scrollToRowAtIndexPath: 一切正常。什么可能导致这种行为?
你可以在这里看到一个截图: