프로토콜이 작동하도록 노력하고 있지만 몇 가지 문제가 있습니다.
내 프로토콜 클래스 .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 ::'를 선언합니다. 여기서 내가 뭘 잘못하고 있습니까?
내가 당신이라면 그렇게 할 것입니다.
@protocol FormViewDelegate <NSObject>
// sent when the user selects a row in the recent searches list
@required
- (void)getDirections:(NSString*)address :(NSString*)cityStateZip;
@end
그런 다음 뷰 컨트롤러 .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;
...
}
그렇게하면 뷰 컨트롤러가 프로토콜 자체를 구현합니다.
도움이 되길 바랍니다
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다