EDIT: beginUpdates and endUpdates works just fine, the immediate collapsing appears to have been an iOS bug that has been quashed.
Part of a redesign of the Numu Tracker interface involved figuring out how to create an expandable TableViewCell in Swift 3 to show and hide the buttons used for navigating to Apple Music or Spotify. I still haven’t found a perfect solution for this (as of Dec 5th, 2016), but this has been my journey and I’ll share it with you…
My first step on my journey was this YouTube video “iOS 8 Expanding Cell Tutorial (Swift)“. His Github has the code necessary for Swift 2, but the entire thing is simple enough that a Swift 3 implementation was easy to write from scratch.
I ran into a problem here however, this is the command used to trigger the animation for the cell expanding and collapsing:
tableView.reloadRows(at: indexPaths, with: UITableViewRowAnimation.automatic)
When performing this reload, it was causing my cell to “flicker”, essentially the text would fade out and back in really quickly. This was distracting and not ideal. I found other people with a similar problem, and the solution was replacing that code with this code:
This works for the most part, except that only the ‘expansion’ animates, the collapse snaps back to the original width. This is not ideal either, but is better than the cell flickering when you tap it. There’s another tutorial on YouTube that uses a combination, where beginUpdates fires, reloadRows next, and endUpdates after that, but there’s still a flash / flicker on his demo app, though it’s not as obvious.
Anyway, this is a fun problem I’m struggling with…