ios - 两个TableView做同步选中行时,选中行高亮效果延迟的问题
ringa_lee
ringa_lee 2017-04-17 15:45:33
0
2
320

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

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

ringa_lee
ringa_lee

ringa_lee

全部回复 (2)
左手右手慢动作

题主说的高亮效果会有延迟,是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; }

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

    大家讲道理

    刚好我最近在做这个,几乎跟你一样.....给大家一个思路,这个是完全可以实现的.你把tableView默认的点击事件用手势屏蔽掉,然后在手势中自己重新定义点击效果,这样就完全可以无延时同步高亮效果了.还有问题来博客找我. blog.cocosdever.com

      最新下载
      更多>
      网站特效
      网站源码
      网站素材
      前端模板
      关于我们 免责声明 Sitemap
      PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!