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
相关推荐
赛博云推-Twitter热门霸屏工具5 小时前
Twitter运营完整流程:从0到引流获客全流程拆解(2026)
运维·安全·自动化·媒体·twitter
M ? A9 小时前
Vue 迁移 React 实战:VuReact 一键自动化转换方案
前端·vue.js·经验分享·react.js·开源·自动化·vureact
梦想的旅途212 小时前
自动化运营如何防封?解析 API 协议下的拟人化风控算法
运维·自动化
清水白石00813 小时前
《Python 架构师的自动化哲学:从基础语法到企业级作业调度系统与 Airflow 止损实战》
数据库·python·自动化
SY.ZHOU14 小时前
移动端架构体系(四):View层的组织与调用方案
flutter·ios·架构·系统架构·安卓
搜狐技术产品小编202314 小时前
智能代码审查基于大语言模型的自动化代码质量保障平台设计与实践
运维·人工智能·语言模型·自然语言处理·自动化
hughnz16 小时前
钻井自动化案例研究
运维·自动化
我科绝伦(Huanhuan Zhou)16 小时前
分享一个MySQL自动化部署平台
mysql·adb·自动化
skywalk816317 小时前
使用官方提供的 bump-pydantic 工具 来自动化部分迁移pydantic代码
运维·自动化
inxx17 小时前
iOS 26 模拟器启动卡死:Method Swizzling 在系统回调时触发 nil 崩溃
ios