开发者

Error: error: expected ')' before 'postData'

开发者 https://www.devze.com 2023-03-02 01:34 出处:网络
How to fix this error ? E开发者_Python百科rror: error: expected \')\' before \'postData\' NSTimer *timer;

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
0

精彩评论

暂无评论...
验证码 换一张
取 消