我有一個顯示時間的標籤;但是,時間不會更新。時間顯示,但不計數。顯示該按鈕的時間並且時間不變。這裏是我的代碼如何每秒更新當前時間?
- (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