Reputation: 3811
I have working code: [self performSelector:@selector(doSomething) ];
but when I change this line to:
[self performSelector:@selector(doSomething) withObject:nil afterDelay:1.0];
it reports error - unrecognized selector....
could you tell me what is the problem in?
thank you
Upvotes: 1
Views: 1047
Reputation: 926
Is self still around? You could be trying to send a message to an NSZombie.
Upvotes: 0
Reputation: 6478
If you changed your method to take an object parameter then you need to change the @selector()
argument to include the ":", e.g., @selector( doSomething: )
This works:
- (void) foo
{
NSLog(@"foo!");
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[self performSelector: @selector(foo) withObject: nil afterDelay: 0.1];
}
So you can pass a selector that takes no param to performSelector:withObject:afterDelay:
and I presume it ignores the withObject:
param which I wasn't 100% sure of.
Upvotes: 5
Reputation: 19071
It looks like your problem is that your selector is doSomething
and not doSomething:
. Without the :
, there's nowhere in the message to insert an object, even nil
.
Upvotes: 1