问题描述
我有工作代码:[self performSelector:@selector(doSomething)];
I have working code: [self performSelector:@selector(doSomething) ];
但是当我将此行更改为:
but when I change this line to:
[[self performSelector:@selector(doSomething)withObject:nil afterDelay:1.0];
[self performSelector:@selector(doSomething) withObject:nil afterDelay:1.0];
它报告错误-无法识别的选择器....
it reports error - unrecognized selector....
你能告诉我问题出在哪里吗?
could you tell me what is the problem in?
谢谢
推荐答案
如果您更改了采用对象参数的方法,则需要更改 @selector()
参数以包括:",例如 @selector(doSomething:)
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: )
这有效:
- (void) foo
{
NSLog(@"foo!");
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[self performSelector: @selector(foo) withObject: nil afterDelay: 0.1];
}
因此您可以将不带参数的选择器传递给 performSelector:withObject:afterDelay:
,并且我想它会忽略我不是100%的 withObject:
参数肯定的.
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.
这篇关于iPhone performSelector问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!