Avoiding Delay from One View Controller to Another in Xcode using Swift

Viewed 143

I have set up a button in my iOS App that performs segue from 1st View Controller to 2nd View Controller. But, there is a delay of about 3-5 seconds on moving from 1st View Controller to 2nd View Controller. Is there any way by which this delay can be avoided and the user can easily go to the 2nd View Controller on the click of the button without any delay? Would appreciate it if anyone could provide any suggestions on how can I eliminate this issue? Thanks a lot for the help:)

@IBAction func startButton(_ sender: Any) {
    
    performSegue(withIdentifier: "1to2segue", sender: self)

}

The 2nd View Controller displays live stats extracted from an external source. Thus, it takes time to load up. How can I make this process faster?

override func viewDidLoad() {
    super.viewDidLoad()

    loadData()

}
1 Answers

In your second view controller, do NOT call your loadData() func in viewDidLoad().

You want to do as little as needed to get the view on the screen. Show a spinner or some other "Loading Data..." activity view.

Then, perhaps in viewDidAppear(), call your loadData() func. But make sure whatever you're doing in loadData() is being done in an async process.

Related