开发者

Difference between performSelector, performSelectorOnMainThread and performSelectorInBackground

What is the difference between

performSelectorOnMainThread

performSelectorInBackground

performSelecto开发者_如何学Gor

Thanks


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 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 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

EDIT:

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜