This is a follow-up to How to get notified when a tableViewController finishes animating the push onto a nav stack.
In a tableView
I want to deselect a row with animation, but only after the tableView has finished animating the scroll to the selected row. How can I be notified when that happens, or what method gets called the moment that finishes.
This is the order of things:
viewWillAppear
I select a certain row.viewDidAppear
I scrollToRowAtIndexPath
(to the selected row).deselectRowAtIndexPath: animated:YES
This way, the user will know why they were scrolled there, but then I can fade away the selection.
Step 4 is the part I haven't figured out yet. If I call it in viewDidAppear
then by the time the tableView scrolls there, the row has been deselected already which is no good.
You can use the table view delegate's scrollViewDidEndScrollingAnimation:
method. This is because a UITableView
is a subclass of UIScrollView
and UITableViewDelegate
conforms to UIScrollViewDelegate
. In other words, a table view is a scroll view, and a table view delegate is also a scroll view delegate.
So, create a scrollViewDidEndScrollingAnimation:
method in your table view delegate and deselect the cell in that method. See the reference documentation for UIScrollViewDelegate
for information on the scrollViewDidEndScrollingAnimation:
method.