I cannot seem to build my protocol the way I would like and I have narrowed down to a problem with using derived classes. If I use a cocoa class it seems to work. Here is what I have...
#import <Foundation/Foundation.h>
#import "MyView.h"
@protocol MyDelegate
- (void)view:(MyView *)aView didDoSomethingWithString:(NSString *)string;
@end
The MyView class is...
#import <UIKit/UIKit.h>
@interface MyView : UIView {
NSString *whatever;
}
- (void)myMethod;
@end
@implementation MyView
- (void)myMethod {
doSomething...
}
@end
So when I attempt to build I get the 开发者_如何学Pythonerror "Expected ')' before 'MyView'". If I replace the custom class MyView with UIView then the code compiles. I am hoping someone sees something that I am overlooking. Any ideas are appreciated.
Thanks.
Are you sure MyView.h contains @interface MyView : UIView
?
Also, instead of importing you can use @class. e.g.
@class MyView;
@protocol MyDelegate
- (void)view:(MyView *)aView didDoSomethingWithString:(NSString *)string;
@end
Try putting the @interface and @implementation parts in different files (if you currently have them in the same file). It looks like you have all that in MyView.m, and you're importing MyView.h, which doesn't exist.
精彩评论