我开始为iPhone开发,因此我在网上看了不同的教程,也try 了一些不同的东西.目前,我正在try 创建一个倒计时,直到午夜.为了得到小时、分钟和秒数,我做了以下操作(我在某处找到了):
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')
这看起来很简单.我错过了什么?
此外,我注意到在不同的地方和不同的时间,星号(*)位于时间NSDate* now
之后或变量NSDate *now
之前.这两者有什么区别?为什么要使用其中一个?