基于我自定義的繼承自UIImageView的一個(gè)CustomImageView;
在.h文件中
1,聲明有這樣一個(gè)協(xié)議:
@protocol CustomImageViewDelegate;
2,緊接著定義一個(gè)屬性:
@property (nonatomic, weak) id<CustomImageViewDelegate>delegate;
3,在結(jié)尾處定義詳細(xì)部分:
@protocol CustomImageViewDelegate<NSObject>
-(void)CustomImageView:(CustomImageView*)cImageView TapedInfo:(NSDictionary*)imageInfo;
@end
在.m文件中
1,給button或則其他空間添加事件。
2,在響應(yīng)事件的方法里:
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
if (self.delegate && [self.delegate respondsToSelector:@selector(CustomImageView:TapedInfo:)]) {
[self.delegate CustomImageView:self TapedInfo:cImageInfo];
}
}
最后在其他應(yīng)用CustomImageView的類里面,在接口處申明遵守此協(xié)議即可,大功告成。