I can’t figure out how to using a method that has an argument with NSTimer. The code i’m using is below – with the idea being a label is sent to the first method where it is turned red and then after a second the second method is called and the label is turned black.
-(void) highlightWord:(UILabel *)label
{
label.textColor = [UIColor colorWithRed:235 green:0 blue:0 alpha:1];
//[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(unhighlightWord:label) userInfo:nil repeats:NO];
}
- (void) unhighlightWord:(UILabel *)label {
label.textColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1];
}
With the code like this, Xcode tells me: Expected ":" after@selector(unhighlightWord:label. If i add in the “:” i get an unrecognized selector message at runtime.
The selector for the timer method takes one argument which is the timer itself (you don’t specify any argument in the selector — it should just be @selector(unhighlightWord:)). So, you need to have an ivar or property that points to your label, and use that in your method, rather than trying to pass the label as an argument.