IPhone performSelector issue

回眸只為那壹抹淺笑 提交于 2019-12-24 09:58:28

问题


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:


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.




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/3126421/iphone-performselector-issue

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!