马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
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
复制代码 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
|