两个TableView做同步选中行时,选中行高亮效果延迟的问题


由于要实现表格横向滚动时第一列保持不动,所以这里用了两个TableView(第一列是一个单独的TableView,右边整个是一个TableView)。然后我通过在tableView: didSelectRowAtIndexPath: 方法里触发另一个表格的selectRowAtIndexPath 事件来实现选中行同步,但是这样的话同步表格的选中行的高亮效果会有延迟,动图中第四次点击可以看得比较明显。

求教有什么比较好的解决方案!

图片描述

ios uitableview

JET你妹 10 years, 3 months ago

题主说的高亮效果会有延迟,是touch cell时间太久导致的,其实一般的click在真机上看不出延迟,模拟器稍微有点一(亲测)。
如果要避免高亮的延时,我能想到的只有touch住的时候不高亮,松开的时候左右tableviewcell一起高亮。

方法:在willSelectRowAtIndexPath设置,不是在didSelectRowAtIndexPath设置


 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ...
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    ...
    return cell;
}

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    UITableViewCell *left_cell=[self.left_tb cellForRowAtIndexPath:indexPath];
    UITableViewCell *right_cell=[self.right_tb cellForRowAtIndexPath:indexPath];

    left_cell.selectionStyle=UITableViewCellSelectionStyleDefault;
right_cell.selectionStyle=UITableViewCellSelectionStyleDefault;

    [self.left_tb selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
    [self.right_tb selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];

    return indexPath;
}

以上代码只能保证第一次点击的时候有上述效果,还需要题主自己完善。

咸鱼人蒋某 answered 10 years, 3 months ago

Your Answer