objective-c – 符合协议的覆盖属性
当我使用LLVM Compiler 2.0时,我似乎正在得到一个新的错误,我以前没有.
我有一个名为DTGridViewDelegate的协议定义为: @protocol DTGridViewDelegate< UIScrollViewDelegate> 我有一个名为 @property(nonatomic,assign)IBOutlet id< DTGridViewDelegate>代表; 现在我得到的消息是: DTGridView.h:116:63:error:属性类型’id< DTGridViewDelegate>‘与类型’id< UIScrollViewDelegate>‘不兼容继承自’UIScrollView’ 因为我已经说过,DTGridViewDelegate符合UIScrollViewDelegate,所以我以为这样可以覆盖这个属性,而且这是第一个建议有一个问题的编译器. 我通过声明属性来修正错误: @property(nonatomic,assign)IBOutlet id< DTGridViewDelegate,UIScrollViewDelegate>代表; 我想知道这是否是编译器问题? 解决方法
您的设置看起来像UITableView从UIScrollView继承的情况中使用的设置相同. UITableViewDelegate协议继承自UIScrollViewDelegate协议.
我设置了以下,编译好的: // .h @protocol ParentClassDelegate -(NSString *) aDelegateMethod; @end @interface ParentClass : NSObject { id delegate; } @property(nonatomic,assign) IBOutlet id <ParentClassDelegate> delegate; @end //.m @implementation ParentClass @synthesize delegate; -(id) delegate{ return @"Parent delegate"; }//-------------------------------------(id) delegate------------------------------------ -(void) setDelegate:(id)someObj{ delegate=someObj; }//-------------------------------------(id) setDelegate------------------------------------ @end //.h @protocol ChildClassDelegate <ParentClassDelegate> -(NSArray *) anotherDelegateMethod; @end @interface ChildClass : ParentClass{ } @property(nonatomic,retain) IBOutlet id <ChildClassDelegate> delegate; @end //.m @implementation ChildClass //@synthesize delegate; -(id) delegate{ return @"childDelegate"; }//-------------------------------------(id) delegate------------------------------------ -(void) setDelegate:(id)someObj{ delegate=someObj; }//-------------------------------------(id) setDelegate------------------------------------ @end 不知道是什么导致你的问题.我会注意到在标题UITableViewDelegate协议看起来像: @protocol UITableViewDelegate<NSObject,UIScrollViewDelegate> 所以也许编译器有时会喜欢更明确的东西. 我建议一个干净的建设.这解决了很多问题. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |