iOS 子类代理与父类的代理冲突的问题

我有一个类XMTextField,继承自类UITextField,UITextField有一个代理

delegate,而我自己的类XMTextField也有自己的代理xdelegate,现在xcode提

示两个警告

1、 propert type XMTextFieldDelegate is incompatible with type

UITextFieldDelegate inherited from UITextField。

2、 Auto property synthesis will not synthesize property

'delegate'; it will be implemented by its superclass,use

@dynamic to...

解决第一警告------遵循父类的协议


@protocol XMTextFieldDelegate<NSObject,UITextFieldDelegate>



@end

解决第二个警告------用@dynamic

@implementation XMTextField
 
@dynamic delegate;






@end

总结:

  1. 第一个就是遵循父类的代理方法
  2. 第二个就是用@dynamic告诉编译器,属性的setter与getter方法由用户自己实现,不自动生成
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容