How do I call performSelectorOnMainThread: with an selector that takes > 1 arguments?

前端 未结 3 1011
不知归路
不知归路 2021-01-30 15:19

A typical call to performSelectorOnMainThread: looks like this:

[target performSelectorOnMainThread:action withObject:foo waitUntilDone:NO];
         


        
3条回答
  •  误落风尘
    2021-01-30 15:44

    In response to a similar question on passing non-objects to a method in performSelectorOnMainThread:, I pointed out Dave Dribin's category on NSObject, which lets you do something like the following:

    [[person dd_invokeOnMainThread] doSomethingWithThing1:thing1 andThing2:thing2 andAlsoThing3:thing3];
    

    for performing your multi-argument method on the main thread. I think this is a pretty elegant solution. Behind the scenes, he wraps things in an NSInvocation, invoking that on the main thread.

    The Amber framework does something similar to this, as well.

提交回复
热议问题