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

红色警告截图
出错部分源码
@interface EGORefreshTableHeaderView : UIView

@property (weak, nonatomic) id  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* delegate;
    
  3. make the protocol be a sub-protocol of NSObject:

     @protocol EGORefreshTableHeaderDelegate 

你可能感兴趣的:(No known instance method for selector 'respondsToSelector:'红色警告导致编译失败)