当你点击UITableView中的一行时,该行会高亮显示并被选中。是否有可能禁用这个,所以点击一行什么都不做?
当前回答
最好的解决方案是使选择样式为None
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
但是,这里我们考虑的事实是,所选状态没有使用自定义图像。
其他回答
你所要做的就是在UITableViewCell实例上设置选择样式:
objective - c:
cell.selectionStyle = UITableViewCellSelectionStyleNone;
or
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
斯威夫特2:
cell.selectionStyle = UITableViewCellSelectionStyle.None
Swift 3和4.x:
cell.selectionStyle = .none
此外,确保你没有在你的表视图委托中实现-tableView:didSelectRowAtIndexPath:或者显式地排除你想要没有动作的单元格。
更多信息在这里和这里
试试这个
cell.selectionStyle = UITableViewCellSelectionStyleNone;
and
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
你也可以使用interfacebuilder设置选择样式。
禁用UItableviewcell的高亮显示
cell.selectionStyle = UITableViewCellSelectionStyleNone;
并且不应该允许用户与单元格交互。
cell.userInteractionEnabled = NO;
你可以使用UITableViewCell的selectionStyle属性
cell.selectionStyle = UITableViewCellSelectionStyleNone;
或
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
同样,不要实现下面的委托
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { ... }
如果你已经创建了Xib/Storyboard文件,那么你可以改变setUserInteractionEnabled 通过取消勾选tableview的属性为No。 这将使你的表视图为只读。
1-你所要做的就是设置UITableViewCell实例的选择样式:
objective - c:
cell.selectionStyle = UITableViewCellSelectionStyleNone;
or
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
斯威夫特2:
cell.selectionStyle = UITableViewCellSelectionStyle.None
斯威夫特3:
cell.selectionStyle = .none
2 -不要实现- tableview:didSelectRowAtIndexPath:在你的表视图中委托或显式地排除你想要没有动作的单元格。
此外,你也可以从故事板。单击表视图单元格,在表视图单元格下的属性检查器中,将Selection旁边的下拉菜单更改为None。
4 -你可以在(iOS) Xcode 9, Swift 4.0中使用下面的代码禁用表格单元格高亮显示
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "OpenTbCell") as! OpenTbCell
cell.selectionStyle = .none
return cell
}
推荐文章
- iPhone上UIView和UILabels的渐变
- keychain上的分发证书中缺少私钥
- 在实现API时,我如何避免在块中捕获自我?
- 如何创建一个Swift Date对象?
- Xcode 4在目标设备上说“finished running <my app>”——什么都没有发生
- 从另一个应用程序打开设置应用程序
- 快速提取正则表达式匹配
- 如何应用梯度的背景视图的iOS Swift应用程序
- 图书馆吗?静态的?动态吗?或框架?另一个项目中的项目
- 如何用SwiftUI调整图像大小?
- Xcode 6 gitignore文件应该包括什么?
- 如何在iPhone/iOS上删除电话号码的蓝色样式?
- 检测视网膜显示
- 如何在UIImageView中动画图像的变化?
- 如何从iPhone访问SOAP服务