It might be useful to make an extension in Swift for this.
Swift 4 and Swift 5:
Swift extension (e.g. in a UITableViewExtension.swift file):
import UIKit
extension UITableView {
func deselectSelectedRow(animated: Bool)
{
if let indexPathForSelectedRow = self.indexPathForSelectedRow {
self.deselectRow(at: indexPathForSelectedRow, animated: animated)
}
}
}
Use e.g.:
override func viewWillAppear(_ animated: Bool)
{
super.viewWillAppear(animated)
self.tableView.deselectSelectedRow(animated: true)
}