disable the uitableview highlighting but allow the selection of individual cells
You can just set the cell's selection style to "None" from Storyboard:
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
Pod Install Displaying Error in Cocoapods Version 1.0.0.Beta.1
How to Dismiss Keyboard When Touching Anywhere Outside Uitextfield (In Swift)
Uitableview Disable Swipe to Delete, But Still Have Delete in Edit Mode
When to Use Uicollectionview Instead of Uitableview
Set Uitableview Content Inset Permanently
iOS App Submission and Beta Review Process
Launch a Local Notification at a Specific Time in iOS
How to Deselect a Selected Uitableview Cell
Scrollview and Keyboard in Swift
Change the Font of a Uibarbuttonitem
Width and Height Equal to Its Superview Using Autolayout Programmatically
How to Change Height of Grouped Uitableview Header
Differencebetween the App Id and the Bundle Id? Where Is the App Id in the Xcode Project
Frosted Glass (iOS 7 Blur) Effect
How to Convert Nsinteger to Nsstring Datatype