erotsppa
erotsppa

Reputation: 15031

performSelectorOnMainThread works but performSelector doesn't why?

I have a selector and target, and calls the method like this

[target performSelectorOnMainThread:(SEL)selector withObject:nil waitUntilDone:FALSE];

But after I changed it to this, it doesn't work

[target performSelector:(SEL)selector withObject:nil afterDelay:0];

Any ideas?

I don't want to perform that task on the main thread because it lags the UI.

By doesn't work I mean that it simply doesn't call the method. I have it im debu mode in simulator and confirmed that it was not called.

Upvotes: 0

Views: 6875

Answers (1)

Nikolai Ruhe
Nikolai Ruhe

Reputation: 81868

I assume you're sending the message from another than the main thread. Cocoa just builds a run loop for the main thread, for other threads you have to build one yourself. The method performSelector:withObject:afterDelay: schedules the message for the next pass through the run loop. So if there is none, the message will not be sent.

For your case, why don't you just send [target performSelector:selector withObject:nil];? You dont need a run loop for that and the message will be sent immediately (on the same thread).

Upvotes: 11

Related Questions