title: Function call in background thread in iOs
body: <p>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:</p>
  
  <pre><code>    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 
                                               (unsigned long)NULL), ^(void) {
          [self download];
      });
  </code></pre>
  
  <p>in this case, the UI didn't lock, but the progress bar didn't come. And I used</p>
  
  <pre><code>    [self performSelectorInBackground:@selector(download) withObject:nil];
  </code></pre>
  
  <p>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. </p>
  
  <p>And the code flow for downloading:</p>
  
  <pre><code>- (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];
  }
  </code></pre>
  
  <p>Please share your ideas</p>