warning: 'NSDate' may not respond to '+currDate'
Above is a warning message when I compile the following code:
-(IBAction)getDate:(id)sender {
currDate = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[ dateFormatter setDateFormat:@"y开发者_Go百科yyy-MM-dd"];
strCurrDate = [dateFormatter stringFromDate:[NSDate currDate]];
displayDate.text = strCurrDate;
[dateFormatter release];
}
I'm just trying to get the current date and display it in a label calleddisplayDate
.
Using the debugger I can see that the date is never converted to a string and stored into strCurrDate
.
The warning message is on the line where I try to use stringFromDate
Can anyone see why this isn't working properly? Any help would be greatly appreciated.
I also currDate is my header file:
NSDate *currDate;
That's because currDate
is not a class method of NSDate
instead it is a property of your class. So this line:
strCurrDate = [dateFormatter stringFromDate:[NSDate currDate]];
should be:
strCurrDate = [dateFormatter stringFromDate:currDate];
精彩评论