When you click on a line in UITableView, the line is highlighted and highlighted. What are the alternatives to this functionality?
3 answers
Your question is not very clear. What alternatives are we talking about? But I will try to answer.
First, when you click on a table cell, the selection may be infected, this is what you called highlighting.
What are the options for selection?
Selection can be turned off completely. This will not highlight, but you will not be able to handle clicking on a cell with the
selectRowAtIndexPathmethod.( default option ) Selection can be enabled for a single cell - single selection . When you click on a cell, it is highlighted, a second click removes the selection, a click on another cell makes it selected, and the previous one stops being selected.
Selection can be enabled for multiple cells - multiple selection . Similar to single selection, with the exception that you can select multiple cells at the same time.
What to do from a practical point of view?
Handle processing . Using the
didSelectRowAtIndexPathmethod,didSelectRowAtIndexPathcan perform some action by clicking on a cell. For example, switching to another controller. It must be borne in mind that after the action the cell remains selected. If the logic of your application does not provide for this, then it is better to remove the selection using the deselectRowAtIndexPath method. By the way, you can also handle selection loss - `didDeselectRowAtIndexPath.Simple backlight . When a cell is selected, it goes into the appropriate state and special styles are applied to its design. They can be set by the properties of the cell -
selectedBackgroundView,multipleSelectionBackgroundView,selectionStyle. It is worth mentioning that the cell may not be selected (selected), but highlighted (highlighted). In this state, special styles are also applied to it, but the call to the selection handler does not occur and is not marked as selected.Group actions All selected cells can be accessed using the
indexPathsForSelectedRowsmethod. These cells can be deleted, hidden, transferred to another controller or to the server.
I highly recommend reading the official documentation:
1) You can remove the highlighting when selected on specific cells:
// вызывая метод: [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; // или по property: cell.selectionStyle = UITableViewCellSelectionStyleNone; 2) You can also completely disable the selection in the table itself:
tableView.allowsSelection = NO; Or set a parameter in Interface Builder:
2) You can add multiple selection. Also in Interface Builder or code:
tableView.allowsMultipleSelection = YES; Note that these two lines include multiple selection:
tableView.allowsSelection = NO; tableView.allowsMultipleSelection = YES; But if you swap them, the selection will be completely disabled.
Make your own views for the background and the highlighted background: cell.backgroundView = redView; cell.selectedBackgroundView = greenView;
You can also add your label for the text, then the native light will not change it.
