user1205315
user1205315

Reputation: 47

Have data retrieved by separate thread returned to main thread for display in UI

I have an application that has a button and a label. When the button is clicked, an asynchronous separate thread is started that calls a Web Service. Once the Service responds, the thread then passes the data back to a function in the MainViewController in the form of an object. However since that function is getting called by the separate thread, it has no way of displaying that data in the UI (main thread). When I try to assign text to a label or change a picture or do any UI manipulation at all, nothing happens.. All UI objects are NULL objects when the function runs. Does anyone have a suggestion as to how I might be able to get data back into the main thread from the spawned thread?

Thought -

I suppose I could store the object in a global variable, but still need to be able to notify the main thread that there is data to go get and display.

Upvotes: 0

Views: 2651

Answers (1)

Joachim Isaksson
Joachim Isaksson

Reputation: 180897

You should really look into Grand Central Dispatch instead of manual threading. If your requirements allow you to use it, it will make your life much simpler when it comes to running things in the background and passing data safely between background threads and the UI thread.

Upvotes: 2

Related Questions