iphone - 如何调用performSelectorOnMainThread : with an selector that takes > 1 arguments?

标签 iphone cocoa-touch selector

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

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

其中“结果”是传递给“操作”的参数。相应的操作是:

- (void)doSomethingWithThing1:(id *)thing1

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

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

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

最佳答案

您可以通过将参数放入字典或数组并将其传递给特殊函数来做到这一点

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

关于iphone - 如何调用performSelectorOnMainThread : with an selector that takes > 1 arguments?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1460589/

相关文章:

iphone - 使用标签栏项目加载 View !

objective-c - 如何在NSTimer循环中刷新TableView Cell数据

ios - 将用户输入的文本更改为 UITextView

jquery - 选择索引大于3且小于6的元素

iphone - iPhone音效

iphone - 有谁知道如何通过 URL 架构在 Apple map 上放置图钉

objective-c - UIViewController 的 View 有奇怪的 20px y 边距

jquery - 编写这个 jQuery 选择器的更好方法

cocoa - 通知中心 : -[NSRunLoop ]: unrecognized selector sent to instance

iphone - 几个 Obj C 问题,包括一个错误