ios - 子类如何继承父类委托(delegate)?

标签 ios delegates

子类扩展父类委托(delegate),子类工作,但有一个警告!!!

父类:

@protocol ObjADelegate;

@interface ObjA : NSObject

@property (nonatomic, assign) id<ObjADelegate> delegate;

- (void)doSth1;

@end

@protocol ObjADelegate <NSObject>

- (void)seeA;

@end

子类:

#import "ObjA.h"

@protocol ObjBDelegate;

@interface ObjB : ObjA

@property (nonatomic, assign) id<ObjBDelegate,ObjADelegate> delegate;

- (void)dosth2;

@end

@protocol ObjBDelegate <ObjADelegate>

- (void)seeB;

@end

它有效,但对类 objB 的委托(delegate)有警告:自动属性合成不会合成属性“委托(delegate)”;它将由其父类(super class)实现,使用@dynamic 确认意图

如何消除这个警告????

最佳答案

提示在警告消息中。您需要在实现中使用 @dynamic 来告诉编译器属性 setter 和 getter 在别处处理(在本例中,由父类(super class)处理)。

@implementation ObjB

@dynamic delegate;

- (void)dosth2 
{

}

@end

关于ios - 子类如何继承父类委托(delegate)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31728831/

相关文章:

ios - 保留和分配有什么区别

ios - 未调用 headerViewForSection

c# - 在 C# 中访问委托(delegate)中的类成员

iOS TableView 不显示数据(调用委托(delegate))

html - 从 UIWebView 在 Safari 中打开特定链接

ios - 如何在tableview中同时插入多行?

ios - Playground 执行失败 : error: Couldn't lookup symbols

ios - 如何使用 libXML 在 xml 文件中获取编码?

linux - 损坏的 ImageMagick 配置

objective-c - Objective-C - 设置 UIPickerView 委托(delegate)