例如,我有一个带有文本“text”的标签,我希望它在5秒内自动更改。如何在5秒内完成动作? 请提供代码示例。
答案 0 :(得分:4)
你想要一个NSTimer
。查看the documentation。您可能需要scheduledTimerWithTimeInterval:invocation:repeats:
或scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:
。这是一个简单的例子:
[NSTimer scheduledTimerWithTimeInterval:5
target:self
selector:@selector(updateString)
userInfo:nil
repeats:NO];
updateString
类似于:
-(void)updateString
{
[textField setStringValue:@"new text"];
}