iOS的performSelectorOnMainThread与多个参数 [英] iOS performSelectorOnMainThread with multiple arguments

查看:388
本文介绍了iOS的performSelectorOnMainThread与多个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从另一个线程在主线程中执行一个选择,但选择具有多个参数,与此类似:

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

- (无效)doSomethingWith:(INT)A B:(浮点)B C:(浮点)C D:(浮点)D E:(浮点),E {
    // ...
}

我怎样才能得到这个工作 performSelectorOnMainThread:withObject:waitUntilDone:

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

修改

我想解释一下为什么我需要这个。

I would like to explain why i need this.

我在主线程上的UIImageViews工作,我为他们计算在另一个线程。我用了很多的计算,所以如果我在主线程使一切,应用滞后。我知道,UI元素只能在主线程上被操纵,这就是为什么我想它这样的工作方式,因此主线程可以听触摸事件没有延迟。

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.

推荐答案

当你使用的是iOS> = 4,你应该这样做,而不是:

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

这就像做 waitUntilDone:NO 。如果你要等到该方法完成后,使用 dispatch_sync 代替。

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

这篇关于iOS的performSelectorOnMainThread与多个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆