0

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
AgRizzo
  • 5,261
  • 1
  • 13
  • 28
  • This sounds like a "bug" I've seen before... Just to test, try adding this line immediately after your `present` line: `DispatchQueue.main.async {}` ... it doesn't look like it should affect anything, but give it a try. – DonMag Jun 12 '17 at 13:18
  • @DonMag - tried it. No improvement. – AgRizzo Jun 12 '17 at 13:36
  • Hmmm... ok, maybe try putting your `present()` line *inside* the `.async{}` braces? `DispatchQueue.main.async { present(promptVC, animated: false, completion: nil) }` By the way - do you have your table cells set to UITableViewCellSelectionStyle.none ? – DonMag Jun 12 '17 at 13:56
  • Are you using auto layout in your view controller because if they are incorrect you can easily end up with constraints that take a long time to calculate or fail and the layout engine spends some time trying to work it out. If so you can test it by disabling all constraints and seeing how quick it appears (it won't look good but it will check for the delay). – Upholder Of Truth Jun 12 '17 at 14:17
  • @DonMag - no improvement by putting it in the async. Also the selection style wasn't set to none. I set it in `cellForRowAt` to none - also no improvement. – AgRizzo Jun 12 '17 at 14:20
  • @UpholderOfTruth - I was using auto layout for QuantityRequestVC. I disabled it. Now it takes 4 seconds to look like garbage. :) – AgRizzo Jun 12 '17 at 14:27
  • If it's still slow then at least you have eliminated the constraints as being the problem. One less thing to worry about. – Upholder Of Truth Jun 12 '17 at 14:43
  • @AgRizzo - it *really* sounds like a UI / thread issue, but... Is your `QuantityRequestVC`really, really complex, that it could be taking that long to set up the first time it's used? What happens if you (temporarily) replace `QuantityRequestVC` with a blank ViewController? – DonMag Jun 12 '17 at 15:00

0 Answers0