我有一个UIImageView的子类,并希望将self作为参数传递给委托。我在MyImageView之前收到错误“Expected')'”。我需要将对象传递给委托,以便委托可以从对象中读取某些属性。
#import <UIKit/UIKit.h>
@protocol MyImageViewDelegate <NSObject>
-(void) buttonPressedForView:(MyImageView *) imageView; //line with ERROR...
@end
@interface MyImageView : UIImageView {
id <MyImageViewDelegate> delegate;
BOOL _imageMode;
}
@property (nonatomic,assign) id <MyImageViewDelegate> delegate;
@property (nonatomic,readonly) BOOL imageMode;
答案 0 :(得分:3)
我认为在协议声明之前你需要MyImageView的前向声明。
@class MyImageView;
@protocol MyImageViewDelegate <NSObject>
-(void) buttonPressedForView:(MyImageView *) imageView;
@end
答案 1 :(得分:0)
也许你应该在定义MyImageView接口后定义协议?似乎该方法无法识别MyImageView类类型,或者只是在新的.h中定义协议并导入当前的.h。
答案 2 :(得分:0)
尝试添加此内容:
#import <UIKit/UIKit.h>
@class MyImageView; <<ADD THIS LINE
@protocol MyImageViewDelegate <NSObject>
-(void) buttonPressedForView:(MyImageView *) imageView; //line with ERROR...
@end
@interface MyImageView : UIImageView {
id <MyImageViewDelegate> delegate;
BOOL _imageMode;
}
@property (nonatomic,assign) id <MyImageViewDelegate> delegate;
@property (nonatomic,readonly) BOOL imageMode;