【发布时间】:2009-11-26 16:02:53
【问题描述】:
我有一个定义 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 控制,它根据滑块值设置它。在 IBAction 中 i 也设置为 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 只是一个空洞,里面什么都没有,好吧,我所做的只是添加评论,
//don't look over here, nothing to see here, oh look at that
如果他们愿意,有人可以关闭它
【问题讨论】:
-
没有看到你的代码就很难说什么......
-
今晚我可以访问有代码的电脑后,我会发布代码
-
对我来说,这似乎是一个非常老套的解决方案。
-
至少它可以工作并且没有内存泄漏