Я столкнулся с этой ошибкой, пытаясь сослаться на протокол, который я сам установил.
Это показывает мой протокол, неправильный метод и то, что я считаю правильным методом.
in .h
// ------------------------------------ EtEmailDelegate Protocol -BEGIN- --------------------------------------
@protocol EtEmailDelegate
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error; //<-- This is really just one chunk from the MFMailComposeViewControllerDelegate
@end
// ------------------------------------ EtEmailDelegate Protocol -END- --------------------------------------
@interface ClsEtEmail : NSObject < MFMailComposeViewControllerDelegate> {
// owner
UIViewController *myUivc;
//EtEmailDelegate *myDelegate; // <--- the wrong way, throw error
id<EtEmailDelegate> *myDelegate; // <-- the right way (i think)
...
}
@property (nonatomic, readwrite, assign) id<EtEmailDelegate> delegate;
@end
Просто для полноты, вот как я реализую некоторые методы, которые также опираются на протокол ...
in .m
@synthesize delegate = myDelegate;
// my static initializer
+(id) objEtEmailWithUivc: (UIViewController*) theUivc delegate: (id <EtEmailDelegate>) theDelegate {
ClsEtEmail * obj = [[[ClsEtEmail alloc] initWithlUivc: theUivc delegate:theDelegate] autorelease];
return obj;
}
// my normal init
- (id)initWithlUivc: (UIViewController*) theUivc delegate: (id <EtEmailDelegate>) theDelegate {
self = [super init];
if (self) {
[self init_]; // my private init (not seen)
self.uivc = theUivc;
NSAssert([theDelegate conformsToProtocol:@protocol(EtEmailDelegate)],@"whoh - this can't is notE tEmailDelegate");
self.delegate = theDelegate;
}
return self;
}
Надеюсь, это поможет кому-то еще.