gpt4 book ai didi

objective-c - 如何使用每 N 秒更改 NSString 的值?

转载 作者:行者123 更新时间:2023-12-03 18:00:05 24 4
gpt4 key购买 nike

我有这段代码每五秒更改一次 NSString 中的数字。

如何让数字保持循环运行?现在它从 1 运行到 19,并在最后一个 (19) 处停止,并在该行上显示 SIGABRT:label.text = ...

在第一个计时器触发之前,如何从显示的第一个数字 (0) 开始?

这是代码:

-(IBAction) rotate3

{


NSString *number = [self.dayArray description];

NSArray *array = [[NSArray alloc] initWithObjects: @"0", @"1", @"2",..., @"19",nil];

number = @"0" ;
numberCount++ ;


self.dayArray = array;
[array release];


label.text = [NSString stringWithFormat:@"Day: %@ ", [dayArray objectAtIndex :numberCount ]];


}

//and the timer

- (void)viewDidLoad

{

timer=[NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(rotate3 )userInfo:nil repeats:YES];

}

最佳答案

这是我的答案:

1)我认为,在最后一个(19),numberCount是20(numberCount++;)。2)只需在调度计时器之前设置该值即可。

关于objective-c - 如何使用每 N 秒更改 NSString 的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8045746/

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