I'm looking for a way to display strings at intervals in an NSTextField
while my application is idle. I know of one way to do this using sleep
although I don't think it's the best way to handle this. I'm thinking NSTimer
scheduledTimerWithTimeInterval
might be a good way to do it, but I'm not sure how to do it.
Here's my code:
- (void)showTextAtInterval {
NSTextField *textLabel;
[textLabel setStringValue:[NSString stringWithFormat:@"06/01/14"]];
sleep(5);
[textLabel setStringValue:[NSString stringWithFormat:@"Headlines"]];
....
}
EDIT: tried this, but only showed "Headlines" statically.
[self startTimer];
- (void)startTimer {
[NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(showTextAtInterval) userInfo:nil repeats:YES];
return;
}
- (void)showTextAtInterval {
NSTextField *textLabel;
[textLabel setStringValue:[NSString stringWithFormat:@"06/01/14"]];
[textLabel setStringValue:[NSString stringWithFormat:@"Headlines"]];
}