iphone dateFromString 给出警告消息“NSDate”可能不会回应“”变量名
warning: 'NSDate' may not respond to '+currDate'
上面是我编译以下代码时出现的警告消息:
-(IBAction)getDate:(id)sender {
currDate = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[ dateFormatter setDateFormat:@"yyyy-MM-dd"];
strCurrDate = [dateFormatter stringFromDate:[NSDate currDate]];
displayDate.text = strCurrDate;
[dateFormatter release];
}
我只是想获取当前日期并将其显示在名为 displayDate
的标签中。 使用调试器,我可以看到日期从未转换为字符串并存储到 strCurrDate
中。
警告消息位于我尝试使用 stringFromDate
的行上,
任何人都可以看到为什么这不能正常工作吗?任何帮助将不胜感激。
我的 currDate 也是我的头文件:
NSDate *currDate;
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:@"yyyy-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;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为
currDate
不是NSDate
的类方法,而是您的类的属性。所以这一行:应该是:
That's because
currDate
is not a class method ofNSDate
instead it is a property of your class. So this line:should be: