我有一个定义 objectAtIndex 的 int,它将它提供给字符串,然后在 UILabel 中显示它,但是,当我修改数组时(在这种情况下添加一个单词),当我让 UILabel 遍历数组时它只显示奇数。我做了一个 NSLog,发现它确实将每一件事都传递给了字符串,但是标签并没有显示每一个,它只是第一次这样做,然后我修改了数组,它只是奇怪
编辑:代码:
- (void) stuff {
NSArray *indivwords = [sentence componentsSeparatedByString:@" "];
count = [indivwords count]; //count=int
if (i < count) {
NSString *chunk = [indivwords objectAtIndex:i];
[word setText:chunk];
NSLog(chunk);
i++;
} else {
word.textColor = [UIColor greenColor];
[word setText:@"DONE"];
}
}
所有这些都由 NSTimer 控制,它根据滑块值将其设置为关闭。i 在 IBAction 中也设置为 0
IBAction 代码:
word.textColor = [UIColor whiteColor];
[timer invalidate];
i = 0;
speedd = (1/speed.value)*60;
timer = [NSTimer scheduledTimerWithTimeInterval:(speedd) target:self selector:@selector(stuff) userInfo:nil repeats:YES];
编辑:
我修好了它!我所做的就是在我达到计数后调用这个
-(void)stoptimer
{
[timer invalidate];
timer = [NSTimer scheduledTimerWithTimeInterval:(.01) target:self selector:@selector(empty) userInfo:nil repeats:YES];
}
empty is just a void with nothing in it, well, all I did was add a comment,
//don't look over here, nothing to see here, oh look at that
Somebody can close this if they want