iOS UICollectionViewCell 点击事件自动化埋点

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
{
 
}

@end
相关推荐
独隅10 小时前
GitHub Actions 自动化运维实战:CI/CD 流水线一体化效果展示
运维·自动化·github
童槿顏丶13 小时前
docker自动化部署脚本
docker·eureka·自动化
具身智能进化论15 小时前
协作机器人产业进入规模化部署期,未来几年的增长从何而来
大数据·运维·人工智能·机器人·自动化·工厂方法模式
微硬创新19 小时前
耐达讯自动化:16路4-20mA模拟信号,该怎样平稳接入PROFINET控制系统?
人工智能·物联网·网络协议·自动化·信息与通信
梦想的旅途219 小时前
企业微信API二次开发:接入 AI 大模型实现外部群智能问答
人工智能·自动化·二次开发·企业微信
Patrick在香港19 小时前
Claude API + Python:香港MPF基金回报率自动化分析框架
windows·python·数据分析·自动化·github·ai编程·数据可视化
lushanzheng20 小时前
2026年必应快排程序:基于 Selenium 自动化解决方案
selenium·测试工具·自动化
mengpp_12345621 小时前
物联网云平台可以离线使用吗?摒弃云端依赖,工业现场离线自动化解决方案
运维·物联网·自动化·华为云
xiaoxiangsiyan21 小时前
企业网络运维自动化与管理协议深度指南
linux·运维·服务器·网络·学习·自动化
梦想的旅途221 小时前
企业微信API二次开发:外部群自动化管理与消息回调实战指南
windows·自动化·企业微信