iOS6 UITableView的节头重复

3

我有一个带有可展开行的UITableView,位于第4个section中。当一个row被展开时,其他的行需要被折叠起来。我重新加载指定的行,并滚动表格使展开的行在顶部。以下是代码:

    - (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:,一切都正常工作。可能是什么原因导致了这种行为?您可以在此处查看屏幕截图:https://istack.dev59.com/SOXqI.webp

1
put titleForHeaderInSection 方法 - iPatel
我在我的问题中添加了viewForHeaderInSection实现。我没有实现titleForHeaderInSection方法。我不得不编辑截图,以便图片不可见。 - user1277152
那么如何显示第1、2节等内容呢? - iPatel
请提供需要翻译的英文内容。 - user1277152
我遇到了完全相同的问题 - 你最终找到解决方法了吗? - Michael
我也有同样的问题,找到任何解决方案了吗? - fdlr
1个回答

0

我曾经遇到过同样的问题。请检查您的代码中是否存在未提交的动画。

[UIView beginAnimations:nil context:NULL];
... should be committed below

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接