방금 Objective-c를 배우는 중이고 MySQL의 타임 스탬프 형식으로 현재 날짜를 생성하는 클래스를 만들려고합니다. 코드를 잘 컴파일하지만 다음과 같은 오류가 발생합니다.클래스를 호출 할 때 NSInvalidArgumentException 수신
012-09-07 08:21:00.368 jsonclient[6831:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[getcurrenttime toString]: unrecognized selector sent to class 0x36a9c'
나는 이것이 간단한 대답 일 것이라고 확신하지만 직접 찾을 수 없습니다. 다음은 클래스와 헤더 및 .m 파일에 대한 나의 호출입니다.
NSString* CurrentDate = [getcurrenttime toString];
#import <UIKit/UIKit.h>
@interface getcurrenttime : NSObject {
NSString *toString;
}
+(NSString*) toString;
@end
#import "getcurrenttime.h"
@implementation getcurrenttime
- (id)init
{
self = [super init];
if (self) {
// Initialization code here.
}
return self;
}
- (NSString*) toString {
NSDate *now =[NSDate date];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
toString = [formatter stringFromDate:now];
return toString;
}
@end
그냥 컴파일러 오류가 발생했습니다. 지금 그것은 말하고있다 'getcurrenttime'에 대한 표시가없는 @interface가 'toString'선택기를 선언한다. – Codeguy007
두 번째 대답 주소. 나는 다른 질문을 읽은 후에 -를 +로 바꿨지 만, 작동하지 않을 때 결코 되돌려 보지 않았다. – Codeguy007
나는 .m 파일에 있었다. 내가 가지고 있던 머리말이었다. 나는 .m 파일에 +를 넣고 구문 오류가 발생했습니다. – Codeguy007