performSelectorOnMainThread

performSelectorOnMainThread

本文介绍了如何调用performSelectorOnMainThread:与选择器,采取> 1个参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

performSelectorOnMainThread:的典型调用如下所示:

A typical call to performSelectorOnMainThread: looks like this:

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

其中result是传递给action的参数。相应的操作是:

where "result" is an argument passed to "action". A corresponding action would be:

- (void)doSomethingWithThing1:(id *)thing1

调用具有> 1个参数的操作的正确语法是什么?如:

What is the correct syntax for calling an action that takes > 1 argument? Such as:

- (void)doSomethingWithThing1:(id *)thing1 andThing2(id *)thing2 andAlsoThing3(id *)thing3

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


推荐答案

响应将非对象传递给中的方法performSelectorOnMainThread: ,我指出Dave Dribin的,它允许您执行如下操作:

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];

在主线程上执行多参数方法。我认为这是一个非常优雅的解决方案。在幕后,他把事情包装在NSInvocation中,在主线程上调用它。

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.

琥珀框架也做类似的事情。

这篇关于如何调用performSelectorOnMainThread:与选择器,采取> 1个参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 08:41