dug*_*gla 14 iphone cocoa-touch selector
典型的调用performSelectorOnMainThread:看起来像这样:
[target performSelectorOnMainThread:action withObject:foo waitUntilDone:NO];
Run Code Online (Sandbox Code Playgroud)
其中"result"是传递给"action"的参数.相应的行动将是:
- (void)doSomethingWithThing1:(id *)thing1
Run Code Online (Sandbox Code Playgroud)
调用> 1参数的动作的正确语法是什么?如:
- (void)doSomethingWithThing1:(id *)thing1 andThing2(id *)thing2 andAlsoThing3(id *)thing3
[target performSelectorOnMainThread:action withObject:??? waitUntilDone:NO];
Run Code Online (Sandbox Code Playgroud)
con*_*are 15
您可以将args放在字典或数组中并将其传递给特殊函数
- (void)doStuff:(NSString *)arg1 and:(NSString *)arg2 and:(NSString *)arg3 {
...
}
- (void)doStuff:(NSArray *)argArray {
[self doStuff:[argArray objectAtIndex:0]
and:[argArray objectAtIndex:1]
and:[argArray objectAtIndex:2];
}
Run Code Online (Sandbox Code Playgroud)
在回答关于将非对象传递给方法的类似问题时performSelectorOnMainThread:,我在NSObject上指出了Dave Dribin的类别,它允许您执行以下操作:
[[person dd_invokeOnMainThread] doSomethingWithThing1:thing1 andThing2:thing2 andAlsoThing3:thing3];
Run Code Online (Sandbox Code Playgroud)
用于在主线程上执行多参数方法.我认为这是一个非常优雅的解决方案.在幕后,他将事物包装在NSInvocation中,在主线程上调用它.
该琥珀框架做一些与此类似,也是如此.
| 归档时间: |
|
| 查看次数: |
25359 次 |
| 最近记录: |