我有一个标签,我想在重新编码触摸时在一段时间内使用多个显示器更新它的文本。我可以使用 performSelector 但它看起来很笨重......
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[self changeTextForLabel:@"A text (1)"]; // When touch begins the display is changed
[self performSelector:@selector(changeTextForLabel:) withObject:@"Another text (2)" afterDelay:1]; // After 1 second update to this
[self performSelector:@selector(changeTextForLabel:) withObject:@"And another text (3)" afterDelay:2]; // after 2 seconds update to this
[self performSelector:@selector(changeTextForLabel:) withObject:@"And even another text (4)" afterDelay:3]; // After 3 seconds update to this
[self performSelector:@selector(changeTextForLabel:) withObject:@"And yes even another text (5)" afterDelay:3]; }
我听说人们谈论使用计时器每 x 秒执行一次方法,但我不明白如何在我的情况下使用它。我有的是..
- (void)updateLabel:(NSTimer *)theTimer {
[self changeTextForLabel:@"A text (1)"];
[self changeTextForLabel:@"Another text (2)"];
[self changeTextForLabel:@"And another text (3)"];
[self changeTextForLabel:@"And even another text (4)"];
[self changeTextForLabel:@"And yes even another text (5)"];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateLabel:) userInfo:nil repeats:YES]; }
但这仅显示最后一条消息..但我希望它在 1 秒后一个接一个地显示。我尝试在每条消息之间使用 pause() 或 sleep() ,但它只会延迟标签更新之前的时间,并使用最后一条消息进行更新。