我有以下标题:
@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
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句