title: Proper thread handling
body: <p>I've come to a problem where proper threading is needed, but I can't seem to optimise it correctly.</p>
  
  <p>Here's my method:</p>
  
  <pre><code>-(void) method1
  {
    // -1 to an NSInteger
    nsint1--;
  
    [self showActiviyIndicator:YES]; //act as loading screen
  
    [alloc database etc stuffs and retrieving of data here]
  
    //for loop here to check with database, and grey out button depending on database values
    for (int i = 1; i&lt;12; i ++)
    {
    //get values from database and store into variables, then grey out the button if variables are 0.
    }
  
    int Val1 = [get from database]
  
    if Val1 = 0
    [button setTitleColor:[UIColor Grey]];
  
    someLabel.text = [NSString stringWithFormat:@"%ld", (long)nsint1];
  
    //here's where the problem lies
    [self refreshTableSessionList:xx];
  
    [self showActiviyIndicator:NO]
  }
  </code></pre>
  
  <p>inside [self refreshTableSessionList:xx], there's a</p>
  
  <pre><code>dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)
  </code></pre>
  
  <p>to get data from server database, then a</p>
  
  <pre><code>dispatch_async(dispatch_get_main_queue(),
  </code></pre>
  
  <p>to populate and reload tableViewCell.</p>
  
  <p>But there'll be a conflict for when I put a </p>
  
  <pre><code>dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)
  </code></pre>
  
  <p>before <code>[alloc database etc stuffs and retrieving of data here]
  </code> and put <code>dispatch_async(dispatch_get_main_queue(),
  </code> when greying out the button, but that's inside a loop, which i don't think it is the right way.</p>
  
  <p>What's the solution to overcome this?</p>