Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I disable the UITableView selection?

When you tap a row in a UITableView, the row is highlighted and selected. Is it possible to disable this so tapping a row does nothing?

like image 291
davidmytton Avatar asked Oct 10 '08 11:10

davidmytton


People also ask

What is UITableView?

UITableView manages the basic appearance of the table, but your app provides the cells ( UITableViewCell objects) that display the actual content. The standard cell configurations display a simple combination of text and images, but you can define custom cells that display any content you want.

What is IndexPath in Tableview Swift?

Swift version: 5.6. Index paths describe an item's position inside a table view or collection view, storing both its section and its position inside that section.


1 Answers

All you have to do is set the selection style on the UITableViewCell instance using either:

Objective-C:

cell.selectionStyle = UITableViewCellSelectionStyleNone; 

or

[cell setSelectionStyle:UITableViewCellSelectionStyleNone]; 

Swift 2:

cell.selectionStyle = UITableViewCellSelectionStyle.None 

Swift 3 and 4.x:

cell.selectionStyle = .none 

Further, make sure you either don't implement -tableView:didSelectRowAtIndexPath: in your table view delegate or explicitly exclude the cells you want to have no action if you do implement it.

More info here and here

like image 200
Martin Gordon Avatar answered Sep 26 '22 15:09

Martin Gordon