What is the difference between setHighlighted
and setSelected
in UITableViewCell
?
If I just want to not highlight a cell
when a selection is made, Should I override setHighlighter
or Just set the selectionStyle
to NONE
.
The cells of UITableView are instances of UITableViewCell or its subclasses. It is the table view that adds, removes, and arranges cells in its view hierarchy. Table views reuse cells that go out of the screen to display new elements, so that:
A UITableViewCell object is a specialized type of view that manages the content of a single table row. You use cells primarily to organize and present your app’s custom content, but UITableViewCell provides some specific customizations to support table-related behaviors, including: Applying a selection or highlight color to the cell.
Table views are more versatile than you might think. For example, many developers make their life harder using a scroll view when a UITableView would be a better choice. Finally, architecture is crucial for table views.
For example, many developers make their life harder using a scroll view when a UITableView would be a better choice. Finally, architecture is crucial for table views. The code of the table view data source often ends inside view controllers when it should go into a separate class.
setHighlighted
will mark the object with a highlighted colour (or glow, depending on your settings) when the finger is touching down. On touch up, the highlight disappears and the object state returns to normal.
setSelected
on the other hand, while similar, will be set on touch down, and will remain in the highlighted state until the next touch down event occurs.
What I think you want is to override setHighlighted
(just return inside the method and don't call super
), but more simply, you can just set the cell's UITableViewCellSelectionStyle
to UITableViewCellSelectionStyleNone
.
To not let the UITableView highlight the cell, implement and return NO in the tableView delegate method - (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath
.
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