在 iOS7 中选择单元格时 UITableView 分隔线消失 [英] UITableView separator line disappears when selecting cells in iOS7
问题描述
在我的 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 错误..),但我找到了一个解决方法.在 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: 必须包含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屋!