例如,我有一个带有文本“text”的标签,我希望它在 5 秒内自动更改。如何让操作在 5 秒内发生?
最佳答案
你想要一个NSTimer
。查看the documentation 。您可能需要 scheduledTimerWithTimeInterval:inspiration: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"];
}
关于objective-c - cocoa 中的计时器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8044200/