I'm a newbie to swift
I have several buttons on 1st View Controller. I'm making different request to server for each button click (from 1st ViewController using Alamofire) & only when I get the response from server as JSON, the 2nd ViewController should be loaded (further I'd dynamically populate the controls on 2nd ViewController by parsing the response JSON data).
My issue is the 2nd View Controller gets loaded up with old data(before response gets loaded for that button click).
My Scenario: (swift 3)
Excuse for not having posted the code(due to some restrictions in workplace). Thanks in advance
You can pass son data received from server in sender parameter of performSegue like this :
let jsonDataReceived = /*Returned data from server (Array or Dictionary )*/
self.performSegue(withIdentifier: "YOUR_SEGUE_ID", sender: jsonDataReceived)
then prepare for segue method you can retrieve your data object :
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "YOUR_SEGUE_ID" {
let jsonDataReceived = sender as? //(Array or Dictionary )
/* intialize you viewController data with jsonDataReceived*/
}
}