Created attachment 18622 [details]
Project to demonstrate the bug
I have been wrestling with an issue that I finally isolated to being related to Presenting a VC from RowSelected vs. other places like a button hit.
I see this on a device running iOS 9.2.1 but not in the iOS10 simulator. My hands are tied testing on other platforms.
When I present a view controller from the RowSelected override in my table source, I see a delay of 5 to 10 seconds before the view controller is loaded and displayed. After the initial presentation, it is usually faster but still sometimes very slow.
After much trial and error and just plain trying stuff, I found that if I presented the ViewController inside a BeginInvokeOnMainThread() handler the delay goes away.
Here is what I had to do. I worked this in a test project that really was not doing anything else. (i.e. - no data retrieval and only UI for test)
public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
var item1VC = new Item1XibController();
vc.PresentViewController(item1VC, true, null);
I have attached source code. I setup the table so that even rows do not call BeginInvokeOnMainThread so are slow and the odds rows do. and are always fast . The button in the header presents the vc without BeginOnvokeOnMainThread and is always fast.
Some logging spits out the time it takes for the vc to appear.
See RowSelected in BrowseTableSource and ItemSelected in BrowseViewController for pertinent code.
First of all thanks for providing a good test case.
For me, time to ViewDidAppear varies from 1478ms (no BeginInvokeOnMainThread) and 575ms when BeginInvokeOnMainThread is called (using the iOS 10 sim though).
Now looking at the current threads and call stack it does not seem the code is running from a background thread so `BeginInvokeOnMainThread` should, technically, not make a difference and yet it does.
We'll have to investigate a bit more, I'm marking this bug as confirmed.