gpt4 book ai didi

ios - 在同一个文件中声明委托(delegate)协议(protocol)

转载 作者:行者123 更新时间:2023-12-01 18:58:15 25 4
gpt4 key购买 nike

我有以下标题:

@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 下面 - 我还有另一个问题,因为委托(delegate)属性不知道@protocol。

我知道我可以将 id、UIView 用于类型,但要保持“强类型”,我该怎么办?我真的不想把它分解成 2 个文件。还有其他选择/建议吗?

最佳答案

使用@class转发声明AttachmentsView像这样:

@class AttachmentsView;

@protocol AttachmentsViewDelegate <NSObject>

// Protocol method declarations...

@end

或者,使用 @protocol前向声明协议(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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com