在我的应用程序中,我有几个TaBleViews,在这些表视图应用程序中进行选择时,可以来回导航。有时在任何表格视图上选择一个单元格都会将选择颜色从默认的灰色变为深黑色,这是随机发生的,这意味着单元格只显示黑色一次,其他时间显示灰色。我不知道为什么会发生这种情况,请提出可能的原因。这是一个iOS错误吗?
截图如下:



发布于 2015-07-28 15:44:08
这不是一个bug,它就像一个标记,表明该单元格已被选中。
如果你不想.selectionStyle = UITableViewCellSelectionStyleNone并保留highlight的灰色;
然后必须取消选择该单元格,如下所示:
Obj-C
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}Swift
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
{
tableView.deselectRowAtIndexPath(indexPath, animated: true)
}发布于 2015-07-28 14:24:45
尝尝这个
在storyboard中选择您的表,单击show the attribute inspector并取消选择Show Selection on Touch选项。
在您didSelectRowAtIndexPath方法中编写
[tableView deselectRowAtIndexPath:indexPath animated:YES];在你的cellForRowAtIndexPath代码中
cell.selectionStyle = UITableViewCellSelectionStyleNone;希望能有所帮助。
https://stackoverflow.com/questions/31668677
复制相似问题