Table View Cell Stays Highlighted No Matter What
<p>My storyboard-based <code>UITableViewController</code> subclass pushes another view controller into the navigation when the user taps one of the table view cells. </p>

<p>I am using a <strong><em>segue</em></strong> to accomplish this, and <strong>not</strong> doing it programmatically with <code>pushViewController(:animated:)</code>.</p>

<p><strong>The problem</strong> I'm having is that my table view cell stays highlighted (light gray) all along, even after popping the view controller (again, with an 'unwind' segue). The only way to clear it is to call <code>tableView.reloadData()</code>.</p>

<hr>

<p>I have tried:</p>

<ol>
<li><p>Setting:</p>

<pre><code>self.clearsSelectionOnViewWillAppear = true
</code></pre>

<p>in <code>viewDidLoad()</code> (Should not be necessary, since it's already the    default: The template code has <code>self.clearsSelectionOnViewWillAppear =     false</code> commented out, and suggests to uncomment it to override the default functionality).</p></li>
<li><p>Also:</p>

<pre><code>override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)

    if let indexPath = tableView.indexPathForSelectedRow {
        tableView.deselectRow(at: indexPath, animated: true)
    }
}
</code></pre>

<p>...to no avail. </p>

<p><strong>EDIT:</strong> Turns out <code>viewDidAppear()</code> is <strong>not</strong> called on navigation pop, only after being added to the view hierarchy (e.g., <code>addSubview()</code>). Placing this code in <code>viewWillAppear()</code> <strong>does</strong> the trick. But my question at the end of this post still stands.</p></li>
<li><p>I have also tried implementing this method:</p>

<pre><code>override func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
    tableView.deselectRow(at: indexPath, animated: true)
}
</code></pre>

<p>...but it is not being called (perhaps because of the segue?) </p></li>
</ol>

<p>The only thing that successfully unhighlights the cell is calling:               </p>

<pre><code>tableView.deselectRow(at: indexPath, animated: true)
</code></pre>

<p>...from within <code>prepareForSegue()</code>. But that happens on <em>push</em>, and I want to de-highlight my cell on <em>pop</em>.</p>

<p>Do I need to setup a dedicated unwind method for the push (cell tap) segue, and unhighlight there? </p>

<p><strong>Why doesn't it work out-of-the-box</strong>, even though I am subclassing <code>UITableViewController</code>?</p>