我按如下方式实现了我的程序。
- (IBAction) toolbarOption:(UIBarButtonItem *)sender
{
switch ([sender tag]) {
case 0:
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:0] animated:YES];
break;
case 1:
for (int i=0; i< [array count]; i++)
{
label02.hidden = YES;
label03.hidden = YES;
label01.text = [array objectAtIndex:i];
order.text = [NSString stringWithFormat:@"%i of %i", i+1,[array count]];
NSDictionary *pronunciation = [[SingletonHandle getHandle] getPronunciationPlist];
label02.text = [pronunciation objectForKey:label01.text];
label03.textColor = [UIColor redColor];
label03.text = [meaning objectForKey:label01.text];
[self performSelector:@selector(showButton:) withObject:nil afterDelay:2.0];
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:nil selector:@selector(showButton:) userInfo:pronunciation repeats:NO];
[timer fire];
}
break;
default:
break;
}
-(IBAction)showButton:(id)sender
{
label02.hidden = NO;
label03.hidden = NO;
nextButton.hidden = NO;
previousButton.hidden = NO;
order.hidden = NO;
}
...
我想将 label.text
显示为 int i 随时间延迟而变化,但它不起作用。它只显示了最后一个 label.text
。我想使用 NSTimer
查看每个 label.text
的时间延迟。
提前谢谢你。
最佳答案
你可以将 NSTimer 用作
theTimer = [NSTimer scheduledTimerWithTimeInterval:1.0f
target:self
selector:@selector(updateTimer:)
userInfo:nil
repeats:YES];`
你可以在函数中更新你的标签
- (void)updateTimer:(NSTimer *)theTimer {
//static int countTime = 0;
countTime += 1;
_timeOver=_timeOver-1;
NSString *s = [[NSString alloc] initWithFormat:@"Time left: %d", (_timeOver)];
self._myTimeCounterLabel.text = s;
[s release];
if (_timeOver==0) {
[self checkIfGameOver];
}
}
关于iphone - 如何延时连续显示标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13468844/