我有一个定义了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控制,NSTimer根据滑块值将其设置为关闭。此外,我在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];  
}

空是一个空洞,里面没有任何东西,好吧,我所做的就是添加评论,

//don't look over here, nothing to see here, oh look at that

有人可以关闭它,如果他们想要

有帮助吗?

解决方案

您说NSTimer的时间间隔由滑块控制。也许您每次更改滑块值时都会启动一个新的计时器实例,因此在更改后您将运行两个计时器。第一个更新标签并递增 i 。第二个在第一个之后,发现 i 的值递增,因此它显示下一个块而不是当前块。

计算你的计时器的实例 - 在计时器回调中对计时器进行NSLog并比较结果 - 可能是你正在激活多个计时器。

其他提示

我的猜测是,当你认为应该有一个时,你有两个不同的动作来调用这个方法。我会在那里放一个断点,看看它是否会停在你想象的位置。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top