Reputation: 11
To start some information about my setup: I have a Storyboard with 3 Views and 3 ViewControllers, one attached to each of the Views.
I'm switching the Views from a completion handler of a DataTask (http request) with self.performSegue(withIdentifier: "bookingSuccess", sender: nil)
. To be able to pass some data I use the prepare function where I assign my ViewModel to the destination Controller.
After that i prepare some UI Stuff in the ViewDidLoad()
function and assign Values to my Labels in the ViewWillAppear()
Method.
This works fine, but when the view switches, half of the UI Elements don't show and the button text is somehow also not there. Under some circumstances, which I don't know (most time after just waiting a few seconds or reopen without closing the APP these Elements are suddenly showing up. I tried a lot of different things and nothing works. Sometimes a label shown up at the beginning, but I haven't got any Idea why it's not displaying. My IOS Target Version is either IOS 10 or IOS 11.0.1/3
Here are two images of the screens: Directly after switching the View
After waiting about 10 seconds
Upvotes: 0
Views: 58
Reputation: 7283
This sounds like a problem with doing UI work on the background thread. Since you are calling self.performSegue(withIdentifier: "bookingSuccess", sender: nil)
from the completion handler of the DataTask and that will be on the background thread so do:
DispatchQueue.main.async {
self.performSegue(withIdentifier: "bookingSuccess", sender: nil)
}
Upvotes: 1