在我的tableView中,我在单元格之间设置了一个分隔线.我允许选择多个细胞.这是我设置所选单元格背景颜色的代码:
UIView *cellBackgroundColorView = [[UIView alloc] initWithFrame:cell.frame];
[cellBackgroundColorView setBackgroundColor:[UIColor darkGray]];
[cell setSelectedBackgroundView:cellBackgroundColorView];
Run Code Online (Sandbox Code Playgroud)
问题是如果选择了两个相邻的单元格,iOS7中它们之间没有分隔线,而iOS6中有(如预期的那样).
我甚至尝试将cellBackgroundColorView帧高设置为cell.frame - 1.0,但这也不起作用.
有任何想法吗?
Mar*_*ark 37
我还没有深究它(乍一看它似乎是一个iOS 7的bug ..),但我找到了一个解决方法.在tableView:didSelectRowAtIndexPath中,如果您发送以下两条消息,则可以直观地解决问题(可能的性能成本).
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
Run Code Online (Sandbox Code Playgroud)
为了这个(对我而言),deselectRowAtIndexPath:animated:必须包含动画:YES.用于reloadRowsAtIndexPaths的动画:withRowAnimation:无关紧要.
小智 24
在单元格中为indexpath处的行添加此代码
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.backgroundColor = [UIColor clearColor];
Run Code Online (Sandbox Code Playgroud)
GOr*_*o58 16
在我的情况下,我是动画一行,所以我需要把这样的东西:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView beginUpdates];
[tableView deselectRowAtIndexPath:indexPath animated:NO];
//if you are doing any animation you have deselect the row here inside.
[tableView endUpdates];
}
Run Code Online (Sandbox Code Playgroud)
Jam*_*far 12
@ samvermette的答案为我解决了这个问题,但我不得不首先取消选择所选的行.
Run Code Online (Sandbox Code Playgroud)- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { //Deselect Row [self.tableView deselectRowAtIndexPath:indexPath animated:YES]; // fix for separators bug in iOS 7 self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine; }
小智 6
在你的 UITableViewCell 类中传递它。
override func layoutSubviews() {
super.layoutSubviews()
subviews.forEach { (view) in
if type(of: view).description() == "_UITableViewCellSeparatorView" {
view.alpha = 1.0
}
}
}
Run Code Online (Sandbox Code Playgroud)
小智 5
当我以编程方式将单元格的选择样式设置为none时,然后以编程方式选择表单元格时,遇到了此问题。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: UITableViewCell!
if tableView == self.jobLevelTableView {
let cell = tableView.dequeueReusableCell(withIdentifier: "cellIdentifier", for: indexPath) as! CheckboxCell
// for testing purposes
let checked = true
// I used M13Checkbox here, in case anybody was wondering
cell.checkbox.setCheckState(checked ? .checked : .unchecked, animated: false)
if checked {
tableView.selectRow(at: indexPath, animated: true, scrollPosition: .none)
}
// CULPRIT
cell.selectionStyle = .none
return cell
}
cell = UITableViewCell()
return cell
}
Run Code Online (Sandbox Code Playgroud)
当我在情节提要板上设置选择样式(并删除等效的代码)时,问题就消失了!
| 归档时间: |
|
| 查看次数: |
28370 次 |
| 最近记录: |