Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
369 views
in Technique[技术] by (71.8m points)

objective c - iOS performSelectorOnMainThread with multiple arguments

I would like to perform a selector on the main thread from another thread, but the selector has multiple arguments, similar to this:

-(void) doSomethingWith:(int) a b:(float)b c:(float)c d:(float)d e:(float)e { //... }

How can I get this working with performSelectorOnMainThread: withObject: waitUntilDone:?

EDIT

I would like to explain why i need this.

I'm working with UIImageViews on the main thread, and I make the calculations for them on another thread. I use a lot of calculations so if i make everything on the main thread, the app lags. I know that UI elements can only be manipulated on the main thread, this is why i would like it to work this way, so the main thread can listen to touch events without lags.

question from:https://stackoverflow.com/questions/8326465/ios-performselectoronmainthread-with-multiple-arguments

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

When you're using iOS >= 4, you'd do this instead:

dispatch_async(dispatch_get_main_queue(), ^{
    [self doSomething:1 b:2 c:3 d:4 e:5];
});

That's like doing waitUntilDone:NO. If you want to wait until the method is finished, use dispatch_sync instead.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...