I have a tab bar based app. There are navigation controllers in all 5 tabs with instances of custom view controller setup properly as root view controllers. This loads just fine. A couple of these view controllers contain table views. I want to show a modal view controller to the user when they select a row in the table view. The (relevant part of) didSelectRowAtIndexPath delegate method looks as follows:
SampleSelectorViewController *sampleVC = [[SampleSelectorViewController alloc] init]; [self presentViewController:sampleVC animated:YES completion:NULL];
The modal view controller appears BUT it appears after a very noticeable delay. At times it even requires the user to tap the row a second time. A few things that I have already verified are:
Any ideas/suggestions?
It seems calling presentViewController:animated:completion
from within tableView:didSelectRowAtIndexPath:
is problematic. It's difficult to find anything that stands out when using the Time Profiler in Instruments, also. Sometimes my modal view comes up in less than a second and other times it takes 4s or even 9s.
I think it's related to the underlying UIPresentationController
and layout, which is one of the few things I see when selecting the region of time between tapping on a row and seeing the modal presentation in the Time Profiler.
A Radar exists describing this issue: http://openradar.appspot.com/19563577
The workaround is simple but unsatisfying: delay the presentation slightly to avoid whatever contentious behavior is causing the slowdown.
dispatch_async(dispatch_get_main_queue(), ^{ [self presentViewController:nav animated:YES completion:nil]; });
If you call present(:animated:completion:) in tableView(:didSelectRowAt:), selectionStyle == .none for selected tableview cell and you’ve got this strange behavior then try to call tableView.deselectRow(at:animated:) before any operations in tableView(_:didSelectRowAt:).
Did it help?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With