Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

maxxiejw

macrumors newbie
Original poster
Nov 21, 2012
1
0
I'm new to Xcode and am in the middle of creating an app and at the moment it can download and save a pdf file from URL. When clicking on the download button, it stays highlighted until the file is downloaded and then the rest of the code is carried out aka. the indicator appears after I've downloaded the file.
I've got the activity indicator code in front of my download code and I've put in an if statement to check the indicator is visible before downloading, but no luck.

Code:
[_downloadActivity startAnimating]; 

if(_downloadActivity.hidden == FALSE){
....... \\download code
}

Any help would be great :) Thanks
 
Last edited by a moderator:
Code:
[_downloadActivity startAnimating]; 

if(_downloadActivity.hidden == FALSE){
....... \\download code
}

Any help would be great :) Thanks

What does the "download code" code look like? It sounds like you are blocking the UI thread while the download is happening, and not giving it a chance to return to the run loop and update the UI.

But that shouldn't happen if you're using something like NSURLConnection.
 
Last edited by a moderator:
I'm new to Xcode and am in the middle of creating an app and at the moment it can download and save a pdf file from URL. When clicking on the download button, it stays highlighted until the file is downloaded and then the rest of the code is carried out aka. the indicator appears after I've downloaded the file.
I've got the activity indicator code in front of my download code and I've put in an if statement to check the indicator is visible before downloading, but no luck.

Code:
[_downloadActivity startAnimating]; 

if(_downloadActivity.hidden == FALSE){
....... \\download code
}

Any help would be great :) Thanks

As the other poster said, you shouldn't be doing synchronous downloading on the main thread. That blocks the UI until the download is complete.

Much better to create an NSURLConnection and start it downloading asynchronously.

If you ARE going to do synchronous network activity, you need to return and service the event loop before starting the download. Something like this:


Code:
[_downloadActivity startAnimating]; 
[self performSelector: @selector(doDownloadStuff) 
  withObject: nil 
  afterDelay: 0];

Then put the code that does the downloading in a method doDownloadStuff. Even though the delay value is 0, the system returns to the main event loop, starts your activity indicator running, and THEN calls your method.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.