gpt4 book ai didi

objective-c - cocoa 中的计时器?

转载 作者:行者123 更新时间:2023-12-03 16:55:17 25 4
gpt4 key购买 nike

例如,我有一个带有文本“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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com