UIViewController's presentViewController:animated:completion: sometimes hangs unless you explicitly call it on the main thread even if it's already on the main thread.

Originator:designatednerd
Number:rdar://18756205 Date Originated:10/23/2014
Status:Open Resolved:
Product:iOS SDK Product Version:8.1
Classification:UI/Usability Reproducible:Sometimes
 
Summary:
In certain circumstances, presenting a view controller modally can hang as if the call is being made from a background thread even if the call is being made from the main thread. The operation sits and spins for anywhere from 0-20 seconds - this can be *wildly* inconsistent, which makes it very hard to diagnose. 

It also isn't happening everywhere. I've been able to get it to reproduce between my actual project and the attached sample project by having a UIViewController with a single UITableView as its subview and a custom UITableView cell as is. The setup of the table view in the sample project mirrors my actual project where the same issue is occurring. 

When this does occur, if you wrap your call to presentViewController:animated:completion in an explicit call either using dispatch_async or [NSOperationQueue mainQueue], it works as expected.

Steps to Reproduce:
1. Open sample project, build and run. 
2. Tap one of the even rows (0 or 2). 
3. Observe that presentation time for the modal can be wildly inconsistent, often taking upwards of 8-9 seconds to present.
4. Tap one of the odd rows (1 or 3). 
5. Observe that the presentation time is consistently as expected. 
6. Drink Heavily. 

Expected Results:
presentViewController:animated:completion: should work the same everywhere as long as it's being called from the main thread. 

Actual Results:
Hair torn out for two days trying to figure out why my VC was taking up to 20 seconds to present even though the call to present was on the main thread. 

Version:
iOS 8.1

Notes:


Configuration:
iPhone 6 Verizon + iOS simulators galore

Attachments:
[If anyone wants a gander at the sample project, email me at designated nerd at gmail dot com, but the workaround is pretty much just wrap your present call in [[NSOperationQueue mainQueue] addOperationWithBlock:] and it works just dandy].

Comments

Just ran the sample project in Xcode 7b1 and it looks like iOS 9 b1 fixes this. Hooray!

By designatednerd at June 11, 2015, 1:55 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!