title: Changing button icon/toggling button from another thread
body: <p>I am trying to run a thread in the background by pressing a button placed on an <code>UITableViewCell</code>.</p>
  
  <p>Now, I have a method that gets called every time the button gets pressed and it changes the icon (from play to pause) and also does other things.</p>
  
  <p>If the thread finishes successfully (although you can stop it with the button on the cell), this button should transition back from the pause icon to play icon, to show that the thread is finished correctly.</p>
  
  <p>I tried passing the cell itself inside the other thread, and then edit the cell button inside <code>dispatch_sync</code>. xCode here doesn't throw any errors, but the button icon does not change.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>-(void)thread:(NSDictionary*)taskAssets{
      @autoreleasepool {
  
          // Unpacking data
          TaskObject *taskData = taskAssets[@"taskData"];
          UILabel *statusLabel = taskAssets[@"statusLabel"];
          CustomTaskCell *cell = taskAssets[@"cell"];
  
          printf("Wow, this is the thread data: %s\n", [taskData.getTaskName UTF8String]);
          sleep(10);
          printf("Wow, the thread is done\n");
          dispatch_sync(dispatch_get_main_queue(), ^{
              [cell setSelected:FALSE];
              [cell.button setImage:[UIImage imageNamed:@"playIcon"] forState:UIControlStateNormal];
              statusLabel.text = @"Status: Finished";
  
          });
      }
  }
  </code></pre>
  
  <p>Is there some way to achieve this?</p>
  
  <p>This is where the icon changing works (yes sender is the button)</p>
  
  <pre><code>- (IBAction)runTask:(id)sender {
      if ([sender isSelected]) {
          [sender setImage:[UIImage imageNamed:@"playIcon"] forState:UIControlStateNormal];
          [sender setSelected:NO];
          [self updateStatus:@"Stopped"];
      } else {
          [sender setImage:[UIImage imageNamed:@"pauseIcon"] forState:UIControlStateSelected];
          [sender setSelected:YES];
          [self updateStatus:@"Running..."];
          [self launchThread]; // This is where the thread starts...
      }
  }
  </code></pre>