我正在尝试扩展 NSImageView 以便我可以将拖放责任委托给控制器。对于编译器现在显示有关向具有类型 id 的对象发送消息的警告的一个问题,这一切都很好。为了解决这个问题,我假设我只需在 ivar 的类型后面加上协议名称即可。但是,这会因无法找到协议定义的消息而惨遭失败。
#import <Cocoa/Cocoa.h>
@interface DragDropImageView : NSImageView {
id <DragDropImageViewDelegate> _delegate;
}
@property (readwrite, retain) id <DragDropImageViewDelegate> delegate;
@end
@protocol DragDropImageViewDelegate
@optional
- (NSDragOperation)dragDropImageView:(DragDropImageView *)ddiv validateDrop:(id <NSDraggingInfo>)info;
- (BOOL)dragDropImageView:(DragDropImageView *)ddiv acceptDrop:(id <NSDraggingInfo>)info;
- (void)concludeDragOperation:(id <NSDraggingInfo>)sender;
@end
任何我可能会出错的指针?我敢肯定它一定很简单,但我对 obj-c 很陌生。