gpt4 book ai didi

iOS7中选择单元格时UITableView分隔线消失

转载 作者:行者123 更新时间:2023-12-02 23:51:00 24 4
gpt4 key购买 nike

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

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

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

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

有什么想法吗?

最佳答案

我还没有弄清楚它的真相(乍一看这似乎是一个 iOS 7 的错误..),但我已经找到了一个解决方法。在 tableView:didSelectRowAtIndexPath 中,如果您发送下面两条消息,问题将得到直观解决(可能会带来性能成本)。

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

要使其工作(对我来说),deselectRowAtIndexPath:animated: 必须包含animated:YES。用于 reloadRowsAtIndexPaths:withRowAnimation: 的动画并不重要。

关于iOS7中选择单元格时UITableView分隔线消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19212476/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com