如何修复此错误?
Error: error: expected ')' before 'postData'
NSTimer *timer;
timer = [NSTimer scheduledTimerWithTimeInterval:10.0 target:self
selector: @selector(postData:@"xyz")
userInfo:nil
repeats: YES];发布于 2011-05-04 10:36:31
从计时器调用为选择器的函数不能有参数。如果我没记错的话,您可以使用userInfo,它将一个数组或字典传递给选择器。
这样做:
NSTimer *timer;
timer = [NSTimer scheduledTimerWithTimeInterval:10.0
target:self
selector: @selector(postData:)
userInfo:@"xyz"
repeats: YES];
- (void)postData:(NSTimer*)timer {
NSLog(@"userInfo = %@", timer.userInfo);
}发布于 2011-05-03 15:44:37
当我们阅读您正在使用的方法的文档时,它似乎没有被正确调用:
timer = [NSTimer scheduledTimerWithTimeInterval:10.0
target:self
selector:@selector(postData:)
userInfo:nil
repeats:YES];并且您的postData必须具有以下签名:
- (void)postData:(NSTimer*)theTimerhttps://stackoverflow.com/questions/5866239
复制相似问题