Search code examples
iphonecocoa-touchuitableviewuikitcore-animation

Deselecting a row in table view does not animate


I have a view controller that manages a table view. My understanding is that a table cell will be deselected automatically if I push another viewcontroller and then pop back to the table view.

However, in the same class (that I use a few times), there is one instance of the class when the cell is deselected but not animated (it'll just turn blue and then back to normal without animating). Why did this happen? I have a few instances of this class but it only happens to one of them. What might be causing this?


Solution

  • From my experience cells are not automatically deselected if you push/pop a view controller (at least not when using a navigationcontroller), unless you add some code te deselect it ! It may also be automatically deselected if you are doing a [tableView reloadData] in viewWill/DidAppear (or in a process started in these methods).

    Did you try to add something like that in viewDidAppear ?

    NSIndexPath *indexPath = [tableView indexPathForSelectedRow];
    if (indexPath != nil) {
        [tableView deselectRowAtIndexPath:indexPath animated:YES]
    }