iOSUICollectionViewCell点击事件自动化埋点
- 电脑硬件
- 2025-09-16 15:36:03

iOS 中经常要进行埋点,我们这里支持 UICollectionViewCell. 进行自动化埋点,思路: 通过hook UICollectionViewCell 的setSelected:方法, 则新的方法中执行埋点逻辑,并调用原来的方法
直接上代码
@implementation UICollectionViewCell (LB) + (void)load { instanceMethodExchangeImplementations([self class], @selector(setSelected:), [self class], @selector(setSelectedWithFilter:)); } -(void)setSelectedWithFilter:(BOOL)selected { // 过滤拼音键盘提示词 if (selected && !self.skipTrack ) { UIView *tempSuperView = self.superview; while (tempSuperView) { if ([tempSuperView isKindOfClass:[UICollectionView class]]) { break; } tempSuperView = tempSuperView.superview; } // 非LBScrllView的cell,才由setSelected触发点击采集,LB cell由didSelected触发, if (tempSuperView && [tempSuperView isKindOfClass:[UICollectionView class]] && ![tempSuperView isKindOfClass:[LBCollectionView class]] && ![tempSuperView isKindOfClass:[LBScrollView class]]) { UICollectionView *collectionView = (UICollectionView *)tempSuperView; if (![collectionView isDragging] && ![collectionView isTracking] && ![collectionView isDecelerating]) { [self setMonitorSelected:selected]; } } } [self setSelectedWithFilter:selected]; } - (void)setMonitorSelected:(BOOL)selected { if (selected && !self.skipTrack) { //执行埋点逻辑 } } - (void)logClickCell { } @endiOSUICollectionViewCell点击事件自动化埋点由讯客互联电脑硬件栏目发布,感谢您对讯客互联的认可,以及对我们原创作品以及文章的青睐,非常欢迎各位朋友分享到个人网站或者朋友圈,但转载请说明文章出处“iOSUICollectionViewCell点击事件自动化埋点”