开发者

iphone dateFromString giving warning message 'NSDate' may not respond to '+ variable name'

开发者 https://www.devze.com 2023-02-14 04:37 出处:网络
warning: \'NSDate\' may not respond to \'+currDate\' Above is a warning message when I compile the following code:
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 called displayDate. 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];
0

精彩评论

暂无评论...
验证码 换一张
取 消