Background
My app (iOS 9.3.5) is based on a UISplitViewController. The detail VC is a tableView. When a row is selected, I want to display a modal VC.
Problem
On an iPad (not an iPhone), the first time a row is selected it takes too long (4 seconds) for the modal to be presented.
- This only occurs when using the iPad (currently configured as
self.splitViewController?.preferredDisplayMode = .allVisible
) - This only occurs the first time a row is selected. Subsequent row selections are quick.
I have isolated the slowness to occur between the present(:animated:completion)
and the modal's viewDidLoad()
. I assume the present(:animated:completion)
is performing some calculations or logic checks which needs to occur the first time because I did not configure the modal correctly or fully. I am trying to find what I did not set up or set up wrongly.
Modal VC setup
From within tableView(:didSelectRowAt:)
:
let promptVC = QuantityRequestVC(nibName: "QuantityRequestVC", bundle: nil)
promptVC.inject(ingredient: fetchedResultsController.object(at: indexPath)) // Loads the selected row's information into view
promptVC.delegate = self // Custom protocol to received information from popover
//Also slow for .fullScreen and .currentContext
promptVC.modalPresentationStyle = UIModalPresentationStyle.popover
let tableCell = tableView.cellForRow(at: indexPath)
promptVC.popoverPresentationController?.sourceView = tableCell
promptVC.popoverPresentationController?.sourceRect = (tableCell?.bounds)!
NSLog("About to present modal")
present(promptVC, animated: false, completion: nil)
NSLog("Just Presented")
Within the QuantityRequestVC's viewDidLoad()
, I also have a NSLog as the very first line.
Sample output:
2017-06-12 08:12:16.047 About to present modal
2017-06-12 08:12:20.943 viewDidLoad entered
2017-06-12 08:12:20.944 super.viewDidLoad finished
2017-06-12 08:12:20.979 Just Presented