iOSUITableVIewCell 主动化点击埋点

[复制链接]
发表于 2025-10-20 22:27:07 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
iOS 中,常常要实现UITableVIewCell 点击埋点,这里通过主动化埋点的方式举行实现。
思绪:通过运行时hook  tableViewCell的 setSelected:animated:方法,
在交换的方法中实现埋点逻辑,并调用原来的实现
cell分类
  1. @property (nonatomic, strong) NSString *actionName;
  2. - (void)setMonitorSelected:(BOOL)selected;
复制代码
  1. #import <objc/runtime.h>
  2. static const void *monitorCellActionNameKey = "monitorCellActionNameKey";
  3. @implementation UITableViewCell (AT)
  4. @dynamic actionName;
  5. + (void)load
  6. {
  7.     instanceMethod_fastExchangeImplementations([self class], @selector(setSelected:animated:), [self class], @selector(setSelectedWithFilter:animated:));
  8. }
  9. -(void)setSelectedWithFilter:(BOOL)selected animated:(BOOL)animated
  10. {
  11.     if (selected && !self.skipTrack) {
  12.         UIView *tempSuperView = self.superview;
  13.         while (tempSuperView) {
  14.             if ([tempSuperView isKindOfClass:[UITableView class]]) {
  15.                 break;
  16.             }
  17.             tempSuperView = tempSuperView.superview;
  18.         }
  19.         // 非LBScrllView的cell,才由setSelected触发点击采集,LB cell由didSelected触发,
  20.         if (tempSuperView && [tempSuperView isKindOfClass:[UITableView class]]
  21.             && ![tempSuperView isKindOfClass:[LBTableView class]] && ![tempSuperView isKindOfClass:[LBScrollView class]]) {
  22.             UITableView *tableView = (UITableView *)tempSuperView;
  23.             if (![tableView isDragging] && ![tableView isTracking] && ![tableView isDecelerating]) {
  24.                 [self setMonitorSelected:selected animated:animated];
  25.             }
  26.         }
  27.     }
  28.     [self setSelectedWithFilter:selected animated:animated];
  29. }
  30. - (void)setMonitorSelected:(BOOL)selected
  31. {
  32.     [self setMonitorSelected:selected animated:NO];
  33. }
  34. -(void)setMonitorSelected:(BOOL)selected animated:(BOOL)animated
  35. {
  36.     if (selected && !self.skipTrack) {
  37.        //埋点操作
  38.   
  39.     }
  40. }
  41. - (NSString *)actionName {
  42.     return objc_getAssociatedObject(self, monitorCellActionNameKey);
  43. }
  44. - (void)setActionName:(NSString *)monitorActionName{
  45.     objc_setAssociatedObject(self, monitorCellActionNameKey,
  46.                              monitorActionName,
  47.                              OBJC_ASSOCIATION_RETAIN_NONATOMIC);
  48. }
  49. @end
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
继续阅读请点击广告
回复

使用道具 举报

×
登录参与点评抽奖,加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表