Error: error: expected ')' before 'postData'
How to fix this error ?
E开发者_Python百科rror: error: expected ')' before 'postData'
NSTimer *timer;
timer = [NSTimer scheduledTimerWithTimeInterval:10.0 target:self
selector: @selector(postData:@"xyz")
userInfo:nil
repeats: YES];
Functions called as selectors from timers cannot have parameters. If I remember correctly, you can use userInfo, which passes an array or dictionary to the selector.
do something like this:
NSTimer *timer;
timer = [NSTimer scheduledTimerWithTimeInterval:10.0
target:self
selector: @selector(postData:)
userInfo:@"xyz"
repeats: YES];
- (void)postData:(NSTimer*)timer {
NSLog(@"userInfo = %@", timer.userInfo);
}
When we read the documentation of the method you are using, it seems it's not correctly called :
timer = [NSTimer scheduledTimerWithTimeInterval:10.0
target:self
selector:@selector(postData:)
userInfo:nil
repeats:YES];
And your postData must have the following signature :
- (void)postData:(NSTimer*)theTimer
精彩评论