viewdidload
{
NSDateFormatter *df = [[[NSDateFormatter alloc] init] init];
[df setDateFormat:@"HH:mm:ss"];
ctime=([df stringFromDate:[NSDate date]]);
NSDate *date1 = [df dateFromString:@"12:44"];`
NSDate *date2 = [df dateFromString:@"20:50"];
NSTimeInterval interval = [date2 timeIntervalSinceDate:date1];
int hours = (int)interval/3600; // integer division to get the hours part
int minutes = (interval - (hours*3600))/60; // interval minus hours part (in seconds) divided by 60 yields minutes
NSString *timeDiff = [NSString stringWithFormat:@"%d:%02d", hours, minutes];
currHour=hours;
currMinute=minutes;
currSeconds=00;
[self start];
}
-(void)start
{
self.timer=[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerFired) userInfo:nil repeats:YES];
}
-(void)timerFired
{
if((currHour>0 || currMinute>0 || currSeconds>=0) && currMinute>=0)
{
if(currSeconds==0)
{
currMinute-=1;
currSeconds=59;
}
else if(currSeconds>0)
{
currSeconds-=1;
}
if(currMinute>-1)
enter code here
[self.timeonelabel setText:[NSString stringWithFormat:@"%d%@%d%@",currHour,@":",currMinute,@":"]];
//[self.hourlabel setText:[NSString stringWithFormat:@"%d%@",currHour,@":"]];
// [self.timeonelabel setText:[NSString stringWithFormat:@"%d%@%d%@",00,@":",currMinute,@":"]];
[self.timetwolabel setText:[NSString stringWithFormat:@"%02d",currSeconds]];
}
else
{
[self.timer invalidate];
}
}
在傳遞當前時間和結束時間的計時器應該運行倒計時爲0 .Problem的定時器沒有運行倒計時,請幫幫我。我甚至停留在顯示計時器倒計時tableview ..請幫助如何倒數計時器上的時間和分鐘和停止時,它的0,目標C
IF((currHour> 0 || currMinute> 0 || currSeconds> = 0)&& currMinute> = 0)執行? – Signare
是執行,currHour不需要編輯代碼。 –
你在哪裏縮短了時間?一個週期完成後,什麼都不會發生? @Shilpa M – Signare