我有以下标题:
@protocol AttachmentsViewDelegate <NSObject>
@required
- (void)spaceRequestedWithSize:(CGSize)size sender:(AttachmentsView*)sender;
@end
@interface AttachmentsView : UIView
@property id<AttachmentsViewDelegate> delegate;
@property NSArray *attachments;
- (void)takePicture;
- (void)deletePictures;
@end
无法使用,因为在@protocol内部,我引用了AttachmentsView,但尚未声明。
如果我将@protocol移到@interface下面-我还有另一个问题,因为委托属性不了解@protocol。
我知道我可以将id,UIView用于类型,但是要使其保持“强类型”,我该怎么办?我真的不希望将其分解为2个文件。还有其他选择/建议吗?
最佳答案
使用@class
像这样转发声明AttachmentsView
:
@class AttachmentsView;
@protocol AttachmentsViewDelegate <NSObject>
// Protocol method declarations...
@end
或者,使用
@protocol
转发声明协议:@protocol AttachementsViewDelegate
@interface AttachmentsView : UIView
// Ivar, method, and property declarations...
@property id<AttachmentsViewDelegate> delegate;
@end
关于ios - 在同一文件中声明委托(delegate)协议(protocol),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24942098/