performSelectorOnMainThread with multiple parameter

前端 未结 2 570
天命终不由人
天命终不由人 2021-01-18 13:46

I am trying to perform this action on the main thread:

[curItem.mButton setBackgroundImage:newArt forState:UIControlStateNormal];

So I do t

2条回答
  •  梦毁少年i
    2021-01-18 14:21

    Another option is GCD. You can invoke a block on the main queue which gets run serially when the run loop runs. blocks aren't limited to one object like performSelectorOnMainThread.

    dispatch_async(dispatch_get_main_queue(), ^{
       // code here
    });
    

    I wrote a more comprehensive comparison of performSelectorXXX and GCD here complete with samples:

    GCD, Threads, Program Flow and UI Updating

    Also, here's another related SO post:

    GCD to perform task in main thread

提交回复
热议问题