Ios rac_signalForSelector:需要空实现

Ios rac_signalForSelector:需要空实现,ios,objective-c,reactive-cocoa,Ios,Objective C,Reactive Cocoa,我有一个实现UICollectionViewDelegate协议的类 我使用rac_signalForSelector:注册选择,如下所示: [self rac_signalForSelector:@selector(collectionView:didSelectItemAtIndexPath:)] - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *

我有一个实现UICollectionViewDelegate协议的类

我使用rac_signalForSelector:注册选择,如下所示:

[self rac_signalForSelector:@selector(collectionView:didSelectItemAtIndexPath:)]
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    // Empty
}
但它只有在collectionView:didSelectItemAtIndexPath:的空实现中离开时才会触发,如下所示:

[self rac_signalForSelector:@selector(collectionView:didSelectItemAtIndexPath:)]
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    // Empty
}
我尝试了rac_Signal for Selector:from Protocol:也没有运气

我用的是反应可可2.2.4

谢谢,
Mikkel

在将对象设置为代理之前,请确保调用
-rac\u signalForSelector:
。一些Apple框架会在您设置委托对象时检查您的类是否响应某个委托方法选择器,并缓存该信息,因此如果您当时没有调用
-rac\u signalForSelector:
,并且没有显式实现该方法,这些委托方法永远不会被调用。

有一个不雅观但可用的解决方法:将
nil
分配为委托,然后重新分配真实的委托对象,这会破坏选择器缓存。如果您在先前分配了一个代表后使用
-rac\u signalForSelector:
,请执行此操作。