To unselect a selected item in a UITableView in Swift, you can simply call the deselectRow
method on the UITableView
instance. Here is a code example:
main.swift179 chars6 lines
In this example, tableView
is the instance of the UITableView
that you want to deselect a row from. The deselectRow
method takes two parameters: the IndexPath
of the row to deselect, and a Bool
value that determines whether the deselection should be animated.
By calling deselectRow
in the didSelectRowAt
method of your UITableViewDelegate
, you can ensure that the selected row is immediately deselected when it is tapped by the user.
gistlibby LogSnag