Cesare Cesare - 6 months ago 10
iOS Question

What is clearsSelectionOnViewWillAppear for?

clearsSelectionOnViewWillAppear
is a boolean property of table and collection views, and it's
true
by default. According to the Apple Reference:


A Boolean value indicating if the controller clears the selection when the table appears.


What does that mean?

Answer

Let's say that, as is usual, you tap a cell and this presents a new view controller. Okay, but how does it do that? Your tap selects the cell. That is a visible change in the cell - the cell is highlighted.

Later, you dismiss that view controller and return to your table / collection view.

The question is: should the selection (caused by your earlier tap) still be showing as a selection? Should the cell still be visibly highlighted? The default is: no. We clear the selection before you visibly return to the table / collection view.

(You could do this yourself in your viewWillAppear: implementation, but the table / collection view controller is willing to do it for you.)

Comments