IPhone performSelector问题

use*_*302 1 iphone selector

我有工作代码:[self performSelector:@selector(doSomething)];

但当我将此行更改为:

[self performSelector:@selector(doSomething)withObject:nil afterDelay:1.0];

它报告错误 - 无法识别的选择器....

你能告诉我这是什么问题吗?

谢谢

Dad*_*Dad 5

如果您更改了方法以获取对象参数,则需要更改@selector()参数以包含":",例如,@selector( doSomething: )

这有效:

- (void) foo
{
    NSLog(@"foo!");
}


- (void)applicationDidFinishLaunching:(NSNotification *)aNotification 
{        
    [self performSelector: @selector(foo) withObject: nil afterDelay: 0.1];
}
Run Code Online (Sandbox Code Playgroud)

所以你可以传递一个不带参数的选择器,performSelector:withObject:afterDelay:我认为它忽略了withObject:我不是100%肯定的参数.