我有一个显示时间的标签;但是,时间不会更新。时间显示,但不计数。显示该按钮的时间并且时间不变。这里是我的代码如何每秒更新当前时间?
- (IBAction)startCamera:(id)sender
{
[self.videoCamera start];
NSDate *today = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"HH:mm:ss"];
NSString *currentTime = [dateFormatter stringFromDate:today];
[dateFormatter setDateFormat:@"dd.MM.yyyy"];
NSString *currentDate = [dateFormatter stringFromDate:today];
for (int i = 1; i <= 10; i--) {
Label1.text = [NSString stringWithFormat:@"%@", currentTime];
Label2.text = [NSString stringWithFormat:@"%@", currentDate];
}
}
我试过一个for循环但不更新时间。有什么建议么?
For循环在基于事件的系统中是讨厌的。我会寻找一些你可以听的活动。 –
调查'NSTimer'。 – rmaddy
@KeithJohnHutchison你是什么意思? – Drizzle