In my iPhone application, I have a button and on the button click I call a web service and getting some links, and after that I need to download the files in those links. On the button click a pop up view will come up and on "OK" click, the button will be replaced with a progress bar and it will show the download progress. And once the download completes, the progress bar will be again replaced by the button. The issue I am having here is, if the internet connection is slow, the UI will blocked and the "Ok" button will be remain in the pressed mode till it completly get the details from the server, only then progress bar will appear. I want to show the progress bar right after the OK button click, it should not lock the UI. I used the following method:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,
(unsigned long)NULL), ^(void) {
[self download];
});
in this case, the UI didn't lock, but the progress bar didn't come. And I used
[self performSelectorInBackground:@selector(download) withObject:nil];
in this case, UI didn't block, but it is showing the download button till it gets the details from the server. Only then it is showing the progress bar.
And the code flow for downloading:
- (void)download{
//Creating a custom progressview
myprogressView = [[CustomProgressView alloc]initWithFrame:CGRectMake(25, 138, 100, 28)];
[cell.contentView addSubview:myprogressView];
[cell bringSubviewToFront:myprogressView];
//Calling the methods for getting the details from the server
//after some internal process, start download
[self.myQueue go];
}
Please share your ideas