When playing around with Hero (I love it so much!) I found that sometimes presenting a view controller on selecting a row would not initiate the transition until some other user action (eg. scrolling the table view) was performed. This smelled of something being innapropriately done off the main thread so I instinctively wrapped my present view controller code in a DispatchQueue.main.async closure and lo and behold it seemed to fix the problem. Thinking about this more though tableView(_:didSelectRowAt:) is already called on the main thread so this is a bit odd.
Defensively adding async closures around this place is a fine solution right now but it would be better not to have to do this suprising trick. Am I missing something, or is this surprising behaviour to others?
If it helps, I found this strange behaviour fairly easy to replicate in the HeroExamples app when selecting a row.
Nice finding. I tried to google it. Seems there are other people who are also experiencing the bug: https://forums.macrumors.com/threads/uitableview-didselectrowatindex-trigger-segue-delay-bug.1894924/
http://stackoverflow.com/questions/28307811/delay-after-didselectrowatindexpath
And your solution is what they have provided. I am not really sure why though. I double checked tableView(_:didSelectRowAt:) method and every time it is hitting the main thread. I would be surprised if it doesn't. Seem to me that this is a bug with how present(_: viewController) is scheduled.
I feel bad for assuming the issue was to do with the library. Thanks for pointing me in the right direction. Turns out you don't even need to put anything in the async block, DispatchQueue.main.async{} after the present view controller was enough.
Have filed a radar with Apple about this. Thanks for the help.
Most helpful comment
I feel bad for assuming the issue was to do with the library. Thanks for pointing me in the right direction. Turns out you don't even need to put anything in the async block,
DispatchQueue.main.async{}after the present view controller was enough.Have filed a radar with Apple about this. Thanks for the help.