我是IOS的新手,但我尽可能地向前跋涉。
我搜索了这个网站和谷歌,但没有找到我的问题的答案,甚至没有答案。
我正在使用文档中声明的方法(我实际上是从网站上借用了这条线来获取以小时为单位的时区偏移量):
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] initWithDateFormat:@"zzz" allowNaturalLanguage:NO];
但编译器错误消息显示:
'NSDateFormatter'没有可见的@interface声明选择器'initWithDateFormat:allowNaturalLanguage:'
当我尝试自动填充功能时,它不会建议使用此init
方法,仅init
和initWithCoder
。
我错过了一些必需的导入吗?我认为这是Foundation.h
的一部分。
非常感谢任何帮助。
感谢。
杰森
答案 0 :(得分:7)
方法NSDateFormatter initWithDateFormat:allowNaturalLanguage:
不属于iOS。该方法仅适用于Mac。对于iOS,请执行:
NSDateFormatter* dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"zzz"];
答案 1 :(得分:2)
你要
No visible @interface for 'NSDateFormatter' declares the selector 'initWithDateFormat:allowNaturalLanguage:'
因为iOS不支持此选择器。只有OS X.
在这篇文章中有更详细的解释: Why is a documented NSDateFormatter init method not getting recognized?
此外,Apple开发人员库非常有帮助。 NSDateFormatter类参考:https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSDateFormatter_Class/Reference/Reference.html。它表示,“iOS注意:iOS仅支持10.4+行为.106风格的方法和格式字符串在iOS上不可用。”链接到新的格式化程序:https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/DataFormatting/DataFormatting.html#//apple_ref/doc/uid/10000029i