1
例如,我有一個帶有文本「文本」的標籤,我希望它在5秒內自動更改。我如何在5秒內做出行動? 請給出一個代碼示例。Cocoa中的計時器
例如,我有一個帶有文本「文本」的標籤,我希望它在5秒內自動更改。我如何在5秒內做出行動? 請給出一個代碼示例。Cocoa中的計時器
你想要一個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"];
}
此外,發送定時'-invalidate'當你如果'重複完成了它:'是'YES'。 – Justin
非常感謝! –