2014-03-29 2 views
0

Xcode에 NSObject 클래스가 있고 @implementation 줄에서 오류가 발생합니다. 'initWithName : tutorID : tutorPhone : tutorEmail :'에 대한 메소드 정의가 없습니다.'initWithName ...'에 대한 메소드 정의를 찾을 수 없습니다. 오류

내 .H 파일 :

#import <Foundation/Foundation.h> 

@interface TutorsItem : NSObject 

@property (nonatomic, strong) NSString *tutorName; 
@property (nonatomic) int tutorID; 
@property (nonatomic, strong) NSString *tutorPhone; 
@property (nonatomic, strong) NSString *tutorEmail; 


- (id)initWithName:(NSString *)tutorName tutorID:(int)tutorID tutorPhone:(NSString *)tutorPhone tutorEmail:(NSString *)tutorEmail; 

@end 

내하는 .m 파일 :

#import "TutorsItem.h" 

@implementation TutorsItem 

@synthesize tutorName = tutorName; 
@synthesize tutorID = tutorID; 
@synthesize tutorPhone = tutorPhone; 
@synthesize tutorEmail = tutorEmail; 

- (id)initWithName:(NSString *)title subtitle:(NSString *)subtitle { 
    self = [super init]; 
    if (self) { 
     self.tutorName = tutorName; 
     self.tutorID = tutorID; 
     self.tutorPhone = tutorPhone; 
     self.tutorEmail = tutorEmail; 

    } 

    return self; 
} 

@end 
+0

정의 또는 구현? – Wain

+0

오류는 ** 정의 ** @Wain –

+3

입니다. 구현 방법이 귀하의 인터페이스 방법과 전혀 일치하지 않는 이유는 무엇입니까? – Wain

답변

0

을 당신은 사람들이 당신이 당신이이 코드

- (id)initWithName:(NSString *)tutorName tutorID:(int)tutorID tutorPhone:(NSString *)tutorPhone tutorEmail:(NSString *)tutorEmail; 

의하지만하는 .m 파일에 다음 줄이 당신의 .H에 당신에게 시도하고있는 무슨 분명 그냥 그렇게 희망 ...

- (id)initWithName:(NSString *)title subtitle:(NSString *)subtitle 

이 일치하지 않는 코드의 2 개 라인을 볼 수 있듯이, 컴파일러는 당신이 .H에서 정의한대로 같은 이름을 가진하는 .m 파일의 방법을 가지고 기대 . 그래서 오류를 제거하기 위해하는 .m 파일이 필요가 다음

- (id)initWithName:(NSString *)tutorName tutorID:(int)tutorID tutorPhone:(NSString *)tutorPhone tutorEmail:(NSString *)tutorEmail 
{ 
    self = [super init]; 
    if (self) { 
     self.tutorName = tutorName; 
     self.tutorID = tutorID; 
     self.tutorPhone = tutorPhone; 
     self.tutorEmail = tutorEmail; 

    } 

    return self; 
} 

다른 사람들은 그냥 당신의 재산과 동일하게 그것을 당신의 매개 변수 이름을 위해 좋은 생각을 지적으로 혼란을 낳습니다.

@synthesize tutorName = tutorName; 

뿐만 아니라이 될 수있는 동일 ... 당신의 @synthesize

이 간다 ...

@synthesize tutorName; 
+0

고맙습니다. 나는 객관적인 C에 새로운 사람이다. 그렇게 말하면서 고마워한다. :) 나는 더 이상 내 컴퓨터에 없지만이 일을 최대한 빨리 시도 할 것이다. –

0

Method defenition not found은이 경고의, 오류가 아닙니다. 그리고 당신은 @implementation 섹션 안에 메서드에 대한 정의를 제공하지 않았기 때문에 그것을 얻습니다. 코드를 컴파일하고 실행할 수는 있지만이 메서드를 호출하면 응용 프로그램이 중단됩니다. 간단하게 정의를 제공하고이 경고는

그리고 BTW이 제거 사라지고 : - (id)initWithName:(NSString *)title subtitle:(NSString *)subtitle 내부

self.tutorName = tutorName; 
    self.tutorID = tutorID; 
    self.tutorPhone = tutorPhone; 
    self.tutorEmail = tutorEmail; 

무엇 당신이 할 것은 아무 의미가 없기 때문입니다. 당신이하는 일은 그들 자신에게 변수 값을 할당하는 것입니다.

0

보고서는 오류가 아닙니다 ("경고가 오류가 발생했습니다"를 제외하고는) 경고가 아닙니다. @interface가 @implementation이 제공하지 않는 메서드를 선언 할 때 일반적인 경고입니다.

@Wain 주석에는 구현시 매우 다른 서명을 가진 init 메소드가 있습니다. 정의한 서명과 일치 시키려고 했습니까? 아니면 두 개의 이니셜 라이저를 제공하겠습니까? @interface에 표시되지 않는 메서드를 사용하는 것은 좋지만, @interface에 표시된 모든 것이 구현되어있을 것으로 예상됩니다. 단지 등등 자막, 그리고 tutorName, tutorId 등을 포함하는 .m 파일에

- (id)initWithName:(NSString *)tutorName tutorID:(int)tutorID tutorPhone:(NSString *)tutorPhone tutorEmail:(NSString *)tutorEmail{ 
    self = [super init]; 
    if (self) { 
     self.tutorName = tutorName; 
     self.tutorID = tutorID; 
     self.tutorPhone = tutorPhone; 
     self.tutorEmail = tutorEmail; 

    } 

    return self; 
} 

함수의 헤더 :

+0

예 경고입니다. 죄송합니다. 하지만 어떻게 고칠 수 있습니까? –

+0

해결 방법 : 누락 된 메서드를 제공하거나 이미 가지고있는 메서드와 일치하도록 인터페이스 정의를 변경하십시오. – mah

+0

그래, 오타가 발견되었습니다. 제목은 tutorName으로되어 있고 부제는 tutorPhone입니다. 그게 고칠 수 있을까요? –

1

당신은 당신의하는 .m 파일을 변경하고 싶습니다. 난이 도움이 :)

+0

그건 그렇고, 아마도 @synthesize 변수 이름을 변경하거나 initWithName 함수에서 변수 이름을 변경하기 때문에 충돌합니다. –

관련 문제