2014-05-19 3 views
0

프로토콜을 작동 시키려고하는데 문제가 있습니다.프로토콜 설정을 올바르게 가져올 수 없습니다.

내 프로토콜 class.h

@protocol FormViewDelegate <NSObject> 
// sent when the user selects a row in the recent searches list 
@required 
- (void)getDirections:(NSString*)address :(NSString*)cityStateZip; 


@end 


@interface BaseFormViewController : NSObject 
@property (nonatomic, weak) id<FormViewDelegate> delegate; 


@end 

내 viewcontroller.h

#import "BaseFormViewController.h" 

@interface ViewController1 : <FormViewDelegate> 

내 viewcontroller.m

@implementation ViewController1 
{ 
    BaseFormViewController *baseProtocol; 
} 

- (IBAction)getDirections:(id)sender { 

    [baseProtocol getDirections:self.address.text :self.cityStateZip.text]; 

} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    baseProtocol = [[BaseFormViewController alloc]init]; 
    baseProtocol.delegate = self; 
    ... 
} 

컴파일러 오류가 나타납니다 : 'BaseFormViewController'에 대한 @interface가 선택자 'getDirections ::'를 선언하지 않습니다. 여기서 내가 뭘 잘못하고 있니?

답변

0

나는 그런 식으로 작업을 수행합니다

@protocol FormViewDelegate <NSObject> 
// sent when the user selects a row in the recent searches list 
@required 
- (void)getDirections:(NSString*)address :(NSString*)cityStateZip; 
@end 

다음보기 controller.h

@interface ViewController1 : <FormViewDelegate> 
@property (nonatomic, weak) id<FormViewDelegate> delegate; 
@end 

다음 뷰 컨트롤러

@implementation ViewController1 

@synthesize delegate 

- (IBAction)getDirections:(id)sender { 

    [baseProtocol getDirections:self.address.text :self.cityStateZip.text]; 

} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    baseProtocol = [[BaseFormViewController alloc]init]; 
    baseProtocol.delegate = self; 
    ... 
} 

그런 식으로 귀하의보기 컨트롤러 구현 당신은 @Required 태그 아래에 기록 된 이후 프로토콜 자체

는 당신이 그렇지 않으면 당신은 점점 당신 경고를 줄 것이다 방법에 대한 해상력을 작성해야한다는 여기

0

ViewController1FormViewDelegate 프로토콜을 준수한다고 명시 했으므로 필수 방법을 구현해야합니다. 내가 당신이라면

@implementation ViewController1 

- (void)getDirections:(NSString*)address :(NSString*)cityStateZip 
{ 
// your implementation 
} 

@end 
0

도움이되기를 바랍니다.

두 태그 아래에 방법을 쓸 수 있습니다. 1) @required :이 태그는 선언하는 모든 메소드이며, 클래스에서 지정해야합니다.

2) @ 선택 사항 :이 태그는 작성중인 모든 선택적 방법 인 선언하는 모든 메소드이며 경고도 표시하지 않습니다.

+0

내가 필요한 곳에서 또는 내가 아직 빌드 오류가 발생했습니다 – BluGeni

+0

무엇이 오류입니까? –

0

간단합니다. BaseFormViewControllerFormViewDelegate에 부합하지 않는 경우 - 그것은이 방법에 대한 지식이없는, 그래서 : 당신이 FormViewDelegate에 적합하게보다 BaseFormViewController에 그 방법을 전달하려는 경우

- (void)getDirections:(NSString*)address :(NSString*)cityStateZip;

합니다. 그리고 (선택 사항) BaseFormViewController에서 대리인 속성을 ViewController1으로 옮깁니다.

관련 문제