Disable the Uitableview Highlighting But Allow the Selection of Individual Cells

disable the uitableview highlighting but allow the selection of individual cells

You can just set the cell's selection style to "None" from Storyboard:

See here

Or from code:

cell.selectionStyle = UITableViewCellSelectionStyleNone;

For Swift 3:

cell.selectionStyle = UITableViewCellSelectionStyle.none

For Swift 4 & above:

cell.selectionStyle = .none

Can I disable the UITableView selection of the individual cell?

cell.selectionStyle = UITableViewCellSelectionStyleNone;

or [cell setSelectionStyle:UITableViewCellSelectionStyleNone];

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.

How can I disable the UITableView selection?

For me, the following worked fine:

tableView.allowsSelection = false

This means didSelectRowAt# simply won't work. That is to say, touching a row of the table, as such, will do absolutely nothing. (And hence, obviously, there will never be a selected-animation.)

(Note that if, on the cells, you have UIButton or any other controls, of course those controls will still work. Any controls you happen to have on the table cell, are totally unrelated to UITableView's ability to allow you to "select a row" using didSelectRowAt#.)

Another point to note is that: This doesn't work when the UITableView is in editing mode. To restrict cell selection in editing mode use the code as below:

tableView.allowsSelectionDuringEditing = false 

Can I disable the UITableView selection of the individual cell?

cell.selectionStyle = UITableViewCellSelectionStyleNone;

or [cell setSelectionStyle:UITableViewCellSelectionStyleNone];

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.

UITableview: How to Disable Selection for Some Rows but Not Others

You just have to put this code into cellForRowAtIndexPath

To disable the cell's selection property: (while tapping the cell)

cell.selectionStyle = UITableViewCellSelectionStyleNone;

To enable being able to select (tap) the cell: (tapping the cell)

// Default style
cell.selectionStyle = UITableViewCellSelectionStyleBlue;

// Gray style
cell.selectionStyle = UITableViewCellSelectionStyleGray;

Note that a cell with selectionStyle = UITableViewCellSelectionStyleNone; will still cause the UI to call didSelectRowAtIndexPath when touched by the user. To avoid this, do as suggested below and set.

cell.userInteractionEnabled = NO;

instead. Also note you may want to set cell.textLabel.enabled = NO; to gray out the item.

How can I disable the UITableView selection?

For me, the following worked fine:

tableView.allowsSelection = false

This means didSelectRowAt# simply won't work. That is to say, touching a row of the table, as such, will do absolutely nothing. (And hence, obviously, there will never be a selected-animation.)

(Note that if, on the cells, you have UIButton or any other controls, of course those controls will still work. Any controls you happen to have on the table cell, are totally unrelated to UITableView's ability to allow you to "select a row" using didSelectRowAt#.)

Another point to note is that: This doesn't work when the UITableView is in editing mode. To restrict cell selection in editing mode use the code as below:

tableView.allowsSelectionDuringEditing = false 

How to disable UITableViewCell highlighting?

Set UITableViewCell selection style none

cell.selectionStyle = .None

Disable selection of a single UITableViewCell

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
UITableViewCell *cell = ...

cell.selectionStyle = UITableViewCellSelectionStyleNone;

}

Disable highlight on tableview

Set the selectionStyle property of your UITableViewCell to .None.
This will permit selection but prevent the default highlighting behavior.



Related Topics



Leave a reply



Submit