出错部分源码
@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继承
解决方案
-
由于respondsToSelector是NSObject的实例方法,所以指定_delegate是一个NSObject实例就可以
[(NSObject *)_delegate respondsToSelector:@selector(egoRefreshTableHeaderDataSourceIsLoading:)]
-
明确指定delegate是一个NSObject实例
@property (weak, nonatomic) NSObject<EGORefreshTableHeaderDelegate>* delegate;
-
make the protocol be a sub-protocol of NSObject:
@protocol EGORefreshTableHeaderDelegate <NSObject>