i want to disable click on particular Cell.it means, i want not to show highlight color(selection indication) when we touch on particular cell? any help please?
Either use cell.selectionStyle = UITableViewCellSelectionStyleNone;
or return false
or return null
in the delegate method tableView:willSelectRowAtIndexPath.
Swift:
If you're using a custom cell:
class YourCustomCell: UITableViewCell {
override func awakeFromNib() {
setup()
}
init() {
setup()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
fileprivate func setup() {
self.selectionStyle = .none
}
}
If you're not using a custom cell:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "CellIdentifierID")
cell.selectionStyle = .none
return cell
}
Bonus: If you want to hide the cell selection and also don't want to call func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {...}
then only set cell.isUserInteractionEnabled = false
. However, this is not a good practice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With