在iOS7中选择单元格时,UITableView分隔线消失 [英] UITableView separator line disappears when selecting cells in iOS7

查看:89
本文介绍了在iOS7中选择单元格时,UITableView分隔线消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的tableView中,我在单元格之间设置了一个分隔线。我允许选择多个细胞。这是我设置所选单元格背景颜色的代码:

In my tableView I set a separator line between cells. I am allowing selection of multiple cells. Here's my code for setting selected cell background color:

UIView *cellBackgroundColorView = [[UIView alloc] initWithFrame:cell.frame];
[cellBackgroundColorView setBackgroundColor:[UIColor darkGray]];
[cell setSelectedBackgroundView:cellBackgroundColorView];

问题是如果选择了两个相邻的单元格,iOS7中它们之间没有分隔线,虽然在iOS6中有(如预期的那样)。

The problem is that if two adjacent cells are selected, there is no separator line between them in iOS7, while there is (as expected) in iOS6.

我甚至尝试将 cellBackgroundColorView 的帧高设置为 cell.frame - 1.0 ,但这也不起作用。

I even tried setting cellBackgroundColorView's frame height to that of cell.frame - 1.0, but that doesn't work either.

有什么想法吗?

推荐答案

我还没有深究它(乍一看它似乎是一个iOS 7的bug ...),但我找到了解决方法。在tableView:didSelectRowAtIndexPath中,如果您发送以下两封邮件,则可以直观地解决问题(可能的性能成本)。

I haven't gotten to the bottom of it yet (at first glance it seems like an iOS 7 bug..), but I have found a workaround. In tableView:didSelectRowAtIndexPath, if you send both messages below, the issue is visually resolved (with the probable performance cost).

[tableView deselectRowAtIndexPath:indexPath animated:YES];
[tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];

为了实现这一点(对我来说),deselectRowAtIndexPath:animated:必须包含动画:YES。用于reloadRowsAtIndexPaths的动画:withRowAnimation:无关紧要。

For this to work (for me), deselectRowAtIndexPath:animated: must contain animated:YES. The animation used for reloadRowsAtIndexPaths:withRowAnimation: doesn't matter.

这篇关于在iOS7中选择单元格时,UITableView分隔线消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆