No known instance method for selector ‘respondsToSelector:’红色警告导致编译失败

释放双眼,带上耳机,听听看~!
红色警告截图
出错部分源码

 

@interface EGORefreshTableHeaderView : UIView

@property (weak, nonatomic) id <EGORefreshTableHeaderDelegate> delegate;

@end

@protocol EGORefreshTableHeaderDelegate

- (void)egoRefreshTableHeaderDidTriggerRefresh:(EGORefreshTableHeaderView *)view;  //触发刷新
- (BOOL)egoRefreshTableHeaderDataSourceIsLoading:(EGORefreshTableHeaderView *)view;  //数据开始加载

@optional

- (NSDate*)egoRefreshTableHeaderDataSourceLastUpdated:(EGORefreshTableHeaderView*)view;  //数据最后更新

@end

and

 

 ...   

if ([_delegate respondsToSelector:@selector(egoRefreshTableHeaderDataSourceIsLoading:)])
{
  _loading = [_delegate egoRefreshTableHeaderDataSourceIsLoading:self];
 }

...
出错原因

声明的协议protocol没有从NSObject继承

解决方案
  1. 由于respondsToSelector是NSObject的实例方法,所以指定_delegate是一个NSObject实例就可以

     

     [(NSObject *)_delegate respondsToSelector:@selector(egoRefreshTableHeaderDataSourceIsLoading:)]
    
  2. 明确指定delegate是一个NSObject实例

     

      @property (weak, nonatomic) NSObject<EGORefreshTableHeaderDelegate>* delegate;
    
  3. make the protocol be a sub-protocol of NSObject:

     

     @protocol EGORefreshTableHeaderDelegate <NSObject>

 

人已赞赏
iOS文章

iOS 13最新原生端适配

2019-12-11 14:39:09

iOS文章

Xcode 11 更新内容

2019-12-11 15:33:43

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
有新消息 消息中心
搜索