当你点击UITableView中的一行时,该行会高亮显示并被选中。是否有可能禁用这个,所以点击一行什么都不做?
当前回答
我正在用这个,它对我很有用。
cell?.selectionStyle = UITableViewCellSelectionStyle.None
其他回答
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
[cell setSelected:NO animated:NO];
[cell setHighlighted:NO animated:NO];
编码快乐!!
你可以使用:
cell.selectionStyle = UITableViewCellSelectionStyleNone;
UITableView的row at index path方法。
你还可以用:
[tableView deselectRowAtIndexPath:indexPath animated:NO];
在tableview中didselectrowatindexpath方法。
快速解决方案,自定义单元:
import Foundation
class CustomTableViewCell: UITableViewCell
{
required init(coder aDecoder: NSCoder)
{
fatalError("init(coder:) has not been implemented")
}
override init(style: UITableViewCellStyle, reuseIdentifier: String?)
{
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.selectionStyle = UITableViewCellSelectionStyle.None
}
}
最好的解决方案是使选择样式为None
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
但是,这里我们考虑的事实是,所选状态没有使用自定义图像。
在UITableViewDelegate协议中,你可以使用willSelectRowAtIndexPath方法 如果你不希望行被选中,返回nil。
同样的,你可以使用willDeselectRowAtIndexPath方法并返回nil,如果你不想让行取消选择。
推荐文章
- 如何使用Xcode创建。ipa文件?
- 动态改变UILabel的字体大小
- 新的自动引用计数机制是如何工作的?
- 在iPhone上确定用户是否启用了推送通知
- 是否有可能禁用浮动头在UITableView与UITableViewStylePlain?
- 错误ITMS-9000:“冗余二进制文件上传。火车1.0版本已经有一个二进制版本上传。
- Swift -转换为绝对值
- 从父iOS访问容器视图控制器
- 自定义dealloc和ARC (Objective-C)
- 调整UITableView的大小以适应内容
- 在代码中为UIButton设置一个图像
- NSRange从Swift Range?
- UICollectionView中的单元格间距
- 我如何在我的iOS应用程序中每n分钟得到一个后台位置更新?
- 如何使用iOS创建GUID/UUID