rac_signalForSelector: needs empty implementation

﹥>﹥吖頭↗ 提交于 2019-12-03 14:15:46

问题


I have a class that implements the UICollectionViewDelegate protocol.

I'm using rac_signalForSelector: to register selection like this:

[self rac_signalForSelector:@selector(collectionView:didSelectItemAtIndexPath:)]

but it only fires if I leave in an empty implementation of collectionView:didSelectItemAtIndexPath: like this:

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    // Empty
}

I tried with rac_signalForSelector:fromProtocol: as well without luck.

I'm using Reactive Cocoa 2.2.4

Thanks, Mikkel


回答1:


Make sure you call -rac_signalForSelector: before you set your object as a delegate. Some Apple frameworks will check to see if your class responds to a certain delegate method selector when you set the delegate object, and cache that information, so if you haven't called -rac_signalForSelector: by that time and you don't explicitly implement the method, those delegate methods won't ever get called.



来源:https://stackoverflow.com/questions/22000433/rac-signalforselector-needs-empty-implementation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!