1

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

Keavon
  • 6,837
  • 9
  • 51
  • 79
user349302
  • 3,491
  • 7
  • 27
  • 31
  • post more code, please. If the ..@selector(doSomething:) does not work, something goes really wrong with your methods – vodkhang Jun 27 '10 at 05:03

3 Answers3

5

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
  • 6,388
  • 2
  • 28
  • 34
  • hmm. your comment to another proposed answer suggests that something else is going on. Post the doSomething method code? – Dad Jun 27 '10 at 04:59
  • 1
    Maybe give us the actual error message, does it say _which_ selector is unrecognized? – Dad Jun 27 '10 at 05:00
1

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
  • 19,021
  • 6
  • 70
  • 80
  • [self performSelector:@selector(doSomething:) withObject:nil afterDelay:1.0]; still the same error – user349302 Jun 27 '10 at 04:55
  • 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 Jun 27 '10 at 06:03
0

Is self still around? You could be trying to send a message to an NSZombie.

Brandon A
  • 926
  • 7
  • 6