I have a simple catalogue app that lets users download product data from an admin website.
The following code is triggered when the user presses the button to initiate a download
- (IBAction)downloadProducts:(id)sender {
outputText.text = @"Downloading data, please wait...";
[Product loadData:outputText];
outputText.text = @"Ok, download complete.";
}
outputText is a UITextView that is supposed to let the user know what’s going on.
There is a static method in the Product class that handles the download. This all works ok, the only problem is that the output to the uitextview blocks until the download is complete.
ie. the “Downloading data, please wait…” message is not displayed until after [Product loadData: outputText]; completes and is instantly overwriting with the download complete message…
Any help much appreciated,
Thanks
jim
Yes, updating the UI will be blocked during your download request. You might need to wait before calling [Product loadData:outputText], which can be done using
and put
in that method.
Or for best practices, start your download on a different thread or using a block. This allows you to keep updating the UI during the download (note that updating the UI should only be done in the main thread/queue)