performSelectorOnMainThread with multiple parameter

前端 未结 2 565
天命终不由人
天命终不由人 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条回答
  •  无人及你
    2021-01-18 14:07

    If you need to pass only one parameter, you should set up "withObject:" argument in method performSelectorOnMainThread:withObject:waitUntilDone. So your method should be declared as

    -(void)setImageForButton:(id)parameter
    

    and you should invoke method on main thread with:

    [obj performSelectorOnMainThread:@selector(setImageForButton:) withObject:newArt waitUntilDone:YES];
    

    Note ':' in @selector(setImageForButton:) this means that this method will be messaged with one argument, passed in withObject:

提交回复
热议问题