PerformSelector: withObject: afterDelay from a class method does not work

Any idea why this is not working?

[self performSelector:@selector(foo:) withObject:argObj afterDelay:5.0]; 

I call this from a class method, and it calls another class method for the same class (hence, "I"). It's really?

I put a breakpoint in foo, but it does not get called. What's going on here?

+6
objective-c iphone
source share
3 answers

Do you have a run loop running in a thread from which you call perform:afterDelay: :? If not, it will not work.

+7
source share

I may not understand your question, but why do you use the self keyword in a static context in the first place? Why not just change self to class name?

-one
source share
 - (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay 

A method is an instance method, the receiver must be an instance of the class. An action requires a specific object. Therefore, I do not think that it will work in a class method.

-one
source share

All Articles