Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between setHighlighted and setSelected in UITableViewCell in iOS?

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.

like image 935
user487257 Avatar asked Dec 10 '15 23:12

user487257


People also ask

What are the cells of UITableView?

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:

What is a uitableviewcell in Salesforce?

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.

Why use a UITableView instead of a Tableview?

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.

Should I use a scroll view or a UITableView?

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.


2 Answers

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.

like image 162
brandonscript Avatar answered Nov 09 '22 21:11

brandonscript


To not let the UITableView highlight the cell, implement and return NO in the tableView delegate method - (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath.

like image 34
Alex Avatar answered Nov 09 '22 22:11

Alex