iOSUITableVIewCell 自动化点击埋点

iOS 中,经常要实现UITableVIewCell 点击埋点,这里通过自动化埋点的方式进行实现。

思路:通过运行时hook tableViewCell的 setSelected:animated:方法,

在交换的方法中实现埋点逻辑,并调用原来的实现

cell分类

复制代码
@property (nonatomic, strong) NSString *actionName;

- (void)setMonitorSelected:(BOOL)selected;

#import <objc/runtime.h>


static const void *monitorCellActionNameKey = "monitorCellActionNameKey";

@implementation UITableViewCell (AT)
@dynamic actionName;

+ (void)load
{
    instanceMethod_fastExchangeImplementations([self class], @selector(setSelected:animated:), [self class], @selector(setSelectedWithFilter:animated:));
}

-(void)setSelectedWithFilter:(BOOL)selected animated:(BOOL)animated
{
    if (selected && !self.skipTrack) {
        UIView *tempSuperView = self.superview;
        while (tempSuperView) {
            if ([tempSuperView isKindOfClass:[UITableView class]]) {
                break;
            }
            tempSuperView = tempSuperView.superview;
        }
        // 非LBScrllView的cell,才由setSelected触发点击采集,LB cell由didSelected触发,
        if (tempSuperView && [tempSuperView isKindOfClass:[UITableView class]] 
            && ![tempSuperView isKindOfClass:[LBTableView class]] && ![tempSuperView isKindOfClass:[LBScrollView class]]) {
            UITableView *tableView = (UITableView *)tempSuperView;
            if (![tableView isDragging] && ![tableView isTracking] && ![tableView isDecelerating]) {
                [self setMonitorSelected:selected animated:animated];
            }
        }
    }
    [self setSelectedWithFilter:selected animated:animated];
}


- (void)setMonitorSelected:(BOOL)selected
{
    [self setMonitorSelected:selected animated:NO];
}

-(void)setMonitorSelected:(BOOL)selected animated:(BOOL)animated
{
    if (selected && !self.skipTrack) {
       //埋点操作 
  
    }
}

- (NSString *)actionName {
    return objc_getAssociatedObject(self, monitorCellActionNameKey);
}

- (void)setActionName:(NSString *)monitorActionName{
    objc_setAssociatedObject(self, monitorCellActionNameKey,
                             monitorActionName,
                             OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

@end
相关推荐
ai大模型中转api测评8 小时前
谷歌Gemma 4突袭发布:开源大模型端侧智能体时代来了
人工智能·自动化·api
A_QXBlms10 小时前
企微私域工具SOP自动化实战:3条核心流程配置教程
大数据·自动化·企业微信
AC赳赳老秦11 小时前
Windows 系统 OpenClaw 执行策略报错及管理员权限设置深度解析与实操指南
运维·人工智能·python·django·自动化·媒体·openclaw
北京耐用通信13 小时前
耐达讯自动化CC-Link IE转EtherCAT网关:让工业自动化更简单
人工智能·科技·物联网·自动化·信息与通信
北京耐用通信13 小时前
架桥记:耐达讯自动化CC-Link IE转EtherCAT的工业协议融合实战
人工智能·科技·物联网·网络协议·自动化
2501_9159184113 小时前
iOS性能测试工具 Instruments、Keymob的使用方法 不局限 FPS
android·ios·小程序·https·uni-app·iphone·webview
CHENKONG_CK13 小时前
晨控 RFID:重塑车载检测全流程智能化管控
网络·自动化·rfid
jikemaoshiyanshi13 小时前
可提供从连接到自动化控制一体化解决方案的主流厂商有哪些?——明确厂商类型定义、厘清能力边界及拆解“一体化”构成要素
其他·自动化
lifewange14 小时前
postman接口自动化如何进行参数化
数据库·自动化·postman
温天仁16 小时前
西门子PLC编程实践教程:工控工程案例学习
开发语言·学习·自动化·php