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
相关推荐
博观而约取厚积而薄发16 小时前
Pytest 从入门到精通,一篇就够(超详细实战教程)
python·测试工具·单元测试·自动化·pytest
imzed16 小时前
使用 Playwright + Pytest 构建 Web UI 自动化测试框架
python·自动化·pytest
交友如交17 小时前
对于Prompt的思考:从“手写”到提示词采样、A/B Test 与自动化评测
人工智能·自动化·prompt
Amy1870211182317 小时前
告别“爬楼抄表”时代:电梯计量自动化改造,让每一度电都“开口说话”
运维·自动化
曦尧17 小时前
开源后台编程 Agent 系统 background-agents:架构拆解与落地判断
ai·自动化
keke.shengfengpolang18 小时前
自动化考什么证书对就业有帮助?
运维·自动化
乐橙开放平台19 小时前
巡店系统笔记:乐橙 listDeviceDetailsByPage 台账 + bindDeviceLive 辅码流最小闭环
网络·笔记·物联网·自动化·音视频·智能家居
程序员吕洞宾19 小时前
开源多维表格SmartTable V1.6.1:工作流画布,让自动化工作流配置更直观、更方便
java·开源·自动化
xo1988201120 小时前
鸿蒙 AI 自动化开发:让 AI 学会自己编译、自己调试
人工智能·自动化·harmonyos
Android出海20 小时前
iOS 出海新门槛:未成年人合规来了
ios·app store·ios开发·苹果开发者·ios开发者·ios出海