这些天在学习iPhone软件开发,在学习到31个iphone软件开发实例教程的时候,首先遇到的是iphone sdk 2.0 miss的问题,我用的是Xcode3.23,it's for Mac OS X10.6 and iPhone OS 4.0。编译下载下来的软件的时候出现错误提示:error: There is no SDK with the name or path 'iphoneos2.0'。
解决的办法是:
1.选择 xCode目录中的"Project".
2.选择 "Edit Project Settings" 子目录.
3.在 "Base SDK for All Configurations"选项中选择iPhone Simulator 4.0.
4.build and run.
但是这个时候编译第一个例程又弹出如下错误:
error: invalid operands to binary - (have 'int' and 'id')
将这段出错代码
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];
替换成如下代码即可顺利通过编译:
NSDate* now = [NSDate date];
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *dateComponents = [gregorian components:(NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit) fromDate:now];
NSInteger hour = [dateComponents hour];
NSInteger minute = [dateComponents minute];
NSInteger second = [dateComponents second];
[gregorian release];
countdownLabel.text = [NSString stringWithFormat:@"%02d:%02d:%02d", hour, minute, second];