【发布时间】:2009-06-10 14:18:30
【问题描述】:
我正在尝试扩展 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 很陌生。
【问题讨论】:
-
+1 提出好问题。
-
关键字是:前向声明。
标签: objective-c macos cocoa-touch cocoa nsdragginginfo