1

Ok, I have looked at performSegueWithIdentifier very slow when segue is modal and tried similar solutions but i am still having a problem - Im working in Swift, and performing a segue based on a tap from a list VC cell takes a good 5-30 seconds. It just hangs there with the bar selected.

I tried speeding this up with

DispatchQueue.main.async {
self.performSegue(withIdentifier: "toPodcastPlayer", sender: self)
}

However all this did was not make the bar select in a color. I need to display a loading screen if this is going to occur, but when with this func for loading:

let loadView = UIView(frame: CGRect(x: 0, y: 0, width: 300, height: 300))
       loadView.backgroundColor = UIColor.green
        loadView.center = CGPoint(x: screenSize.width/2, y: screenSize.height/2)
        view.addSubview(loadView)

And this when tapped:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

        let selectedIndexPath : [IndexPath] = self.myTableView.indexPathsForSelectedRows!



     if(self.rssListToLoad[selectedIndexPath[0].row].link != "")
       {
        showLoading()
        self.performSegue(withIdentifier: "toPodcastPlayer", sender: self)
        }

and

if segue.identifier == "toPodcastPlayer" {
            // find index path for selected row
            let selectedIndexPath : [IndexPath] = self.myTableView.indexPathsForSelectedRows!

            // deselect the selected row
            self.myTableView.deselectRow(at: selectedIndexPath[0], animated: true)

            // create destination view controller
            let destVc = segue.destination as! PodcastViewController

            // set title for next screen
            destVc.adTxtName = "Skylar's Ad"
            destVc.urlStr = self.rssRecordList[selectedIndexPath[0].row].link
            destVc.trackLabel = self.rssRecordList[selectedIndexPath[0].row].title

It is still delayed. I don't understand this since the view is already created in the storyboard and just has to set some variables in the next VC. What is wrong here?

My segue type is a present modally, not deprecated.

Rishil Patel
  • 1,977
  • 3
  • 14
  • 30
blue
  • 7,175
  • 16
  • 81
  • 179
  • Have you tried profiling it in Instruments to see what's taking so long? Your calls to `didSelectRowAtIndexPath()` are already on the main thread, and should not be async calls, so you don't need to use GCD here. What is happening in your `PodcastViewController` when you set those properties? – Craig Otis Jun 28 '17 at 22:26
  • 2
    Once you call `performSegue` then the segue is essentially committed (you can abort it by returning `false` from `shouldPerformSegue`). If you need to show a loading UI you should do so in the destination view controller. You also need to ensure that any loading is performed asynchronously on a background thread. Once the load is complete you remove the loading UI and displayed the loaded data. – Paulw11 Jun 28 '17 at 22:26
  • My problem is regardless of what I do in the destination, the "loading" time delay occurs on the list VC, then a little bit in the destination. If I try to show a loading like I said in the list view, it doesn't show it until the segue starts actually working – blue Jun 29 '17 at 11:12
  • @CraigOtis the podcast view starts streaming an m4a and plays it in view did load, which takes a little bit of time once the segue goes to trough, but I don't unders and why some loading would occur on the selected view BEFORE it even comes up. Should I delay the play function in the destination even though I want it to play when it gets there? – blue Jun 29 '17 at 11:15

1 Answers1

0

After reading your question it seems that same problem I encountered in my last app, after trying lots of solutions I came to know that this is an open bug from Apple, you can look here for more information: http://openradar.appspot.com/19563577

Note: Please do perform segue on the main thread, it will solve your 'delay' problem of presenting controller.

here's code to do that :

    let vc =  controller as! ViewController

    vc.modalPresentationStyle = .custom

    DispatchQueue.main.async {
         self.present(vc, animated: false, completion: nil)
    }
Jarvis The Avenger
  • 2,750
  • 1
  • 19
  • 37