原来的程序:
- -(void)updateLabel {
- NSDate* now = [NSDate date];
- int hour = 23 – [[now dateWithCalendarFormat:nil timeZone:nil] hourOfDay];
- int min = 59 – [[now dateWithCalendarFormat:nil timeZone:nil] minuteOfHour];
- int sec = 59 – [[now dateWithCalendarFormat:nil timeZone:nil] secondOfMinute];
- countdownLabel.text = [NSString stringWithFormat:@“%02d:%02d:%02d”, hour, min,sec];
- }
这些函数在Xcode4中不识别,
需要改成:
- -(void)updateLabel{
- NSCalendar *calendar=[[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];
- NSInteger unitFlags=NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
- NSDate *date=[NSDate date];
- NSDateComponents *comps=[calendar components:unitFlags fromDate:date];
- int hour=23-[comps hour];
- int min=59-[comps minute];
- int sec=59-[comps second];
- countdownLabel.text=[NSString stringWithFormat:@“%02d:%02d:%02d”,hour,min,sec];
- }
原文地址:
关于31天App教程示例中一些因SDK版本而出现的问题