我开始为 iPhone 开发,因此我在网上查看不同的教程,并自己尝试一些不同的东西。目前,我正在尝试创建一个倒计时直到午夜。为了获得小时、分钟和秒的数量,我执行以下操作(我在某处找到):
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];
但是,我使用-dateWithCalendarFormat:timeZone:
的每个地方都会出现以下错误:
warning: 'NSDate' may not respond to '-dateWithCalendarFormat:timeZone:'
(Messages without a matching method signature will be assumed to return 'id' and accept '...' as arguments.)
warning: no '-hourOfDay' method found
error: invalid operands to binary - (have 'int' and 'id')
这看起来很简单。我错过了什么?
另外,我注意到在不同的地方和不同的时间,星号 (*) 位于 time 之后NSDate* now
或变量之前NSDate *now
。两者有什么区别,为什么要使用其中一个而不是另一个?