performSelector,performSelectorOnMainThread和performSelectorInBackground之间的区别 [英] Difference between performSelector, performSelectorOnMainThread and performSelectorInBackground

查看:135
本文介绍了performSelector,performSelectorOnMainThread和performSelectorInBackground之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么区别

performSelectorOnMainThread

performSelectorOnMainThread

performSelectorInBackground

performSelectorInBackground

performSelector

performSelector

谢谢

推荐答案

performSelector将简单按照它所说的去做,当你想使用它的名字作为NSString执行一个选择器时,通常会使用它,这在以编程方式构建选择器名称的情况下很有用。如果您熟悉Java,可以将它与反射进行松散的比较。

performSelector will simply do what it says, usually you would use this when you want to execute a selector using it's name as an NSString, this is useful in situations where you programatically build the name of a selector. If you are familiar with Java you could loosely compare it with reflection.

performSelectorInBackground将在后台的新线程中异步执行选择器,这样您就可以在不锁定UI的情况下发送长任务

performSelectorInBackground will execute the selector asynchronously in a new thread in the background so that you can send off long tasks without locking up your UI

performSelectorOnMainThread将简单地在应用程序主线程上执行选择器。这有可能冻结ui,你可以保留它来执行明确更新ui的任务

performSelectorOnMainThread will simply perform the selector on your applications main thread as it states. This has the potential of freezing the ui, you might reserve it to do tasks that update the ui explicitly

编辑:

performSelectorOnMainThread 上还有更多内容,当您从后台运行的线程中调用它时,这非常有用。例如,您有一个线程在后台处理任务并且您想要更新状态标签,只有在主线程上运行的线程才会更新UI,因此您可以使用<$ c $调用更新状态标签的选择器c> performSelectorOnMainThread

Some more on performSelectorOnMainThread, this is most useful when you you're calling it from a thread running in the background. An example would be you have a thread processing a task in the background and you want to update a status label, only threads running on the main thread will update the UI so you would call your selector that updates the status label using performSelectorOnMainThread

这篇关于performSelector,performSelectorOnMainThread和performSelectorInBackground之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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