0

I would like to update my model object before my main view controller loads. Currently, the code for updating the views are running before my model receives the data from the server, so the main view displays the wrong data.

I am using PubNub. There is a listener set up in the appdelegate that triggers when data is received.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • 1
    You need to implement something like `updateData` to load from backend and reload your `viewController` this with some loading indicator, Is not a good practice hold on anything on your main thread waiting for server response – Reinier Melian Jun 08 '16 at 22:39
  • 3
    You don't want to delay `viewDidLoad` for any reason. It's a bad UX and if it happens at the wrong time, the watch dog process can kill your app (0x8badf00d; lol). Instead, you should have your app show the last known data and/or some dimming view and/or `UIActivityIndicatorView` to let the user know that more data is coming in. – Rob Jun 08 '16 at 22:39

1 Answers1

3

Don't ever delay viewDidLoad()- you need to have a blank/loading screen to display when there is no data to present. Once that data arrives- have it call an update function to display it.

Cesar
  • 2,027
  • 2
  • 18
  • 29
  • 2
    I agree with Cesar. Trying to delay viewDidLoad is bad mojo, and would likely cause your app to be terminated since the system would think it was hung. You need to display SOMETHING while you are waiting on the server. A floating "loading, please wait" view with an activity indicator is one possibility. – Duncan C Jun 08 '16 at 22:48