views:

50

answers:

2

Hello

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

+1  A: 

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.

Jeff Kelley
[self performSelector:@selector(doSomething:) withObject:nil afterDelay:1.0];still the same error
See below, simple test code that shows that you don't seem to have to have a selector that takes an object when using `peformSelector:withObject:afterDelay:`... (I wasn't sure on this so had to write a quick test to confirm).
Dad
+2  A: 

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.

Dad
hmm. your comment to another proposed answer suggests that something else is going on. Post the doSomething method code?
Dad
Maybe give us the actual error message, does it say _which_ selector is unrecognized?
Dad