Toggle navigation
Toggle navigation
This project
Loading...
Sign in
mobile
/
YH_EventReport
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
孙凯
7 years ago
Commit
417a180ea76b155dadc8ef8e5eda9579b8b69424
1 parent
ab76d455
修改 tableview hook逻辑 review by daiqiang
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
25 deletions
YHEventReport/YHEventReport/YHEventReport/YH_AOP/UITableView+AutoTrack.m
YHEventReport/YHEventReport/YHEventReport/YH_AOP/UITableView+AutoTrack.m
View file @
417a180
...
...
@@ -115,35 +115,22 @@ void yher_tableViewDidSelectRowAtIndexPath(id self, SEL _cmd, id tableView, NSIn
@try
{
SEL
swizzledMethodSEL
=
@selector
(
tableView
:
didSelectRowAtIndexPath
:
);
if
(
!
[
delegate
respondsToSelector
:
swizzledMethodSEL
])
{
SEL
originMethodSEL
=
@selector
(
collectionView
:
didSelectItemAtIndexPath
:
);
if
(
!
[
delegate
respondsToSelector
:
originMethodSEL
])
{
return
;
}
Class
c
lass
=
[
delegate
class
];
Class
delegateC
lass
=
[
delegate
class
];
SEL
originMethodSEL
=
NSSelectorFromString
(
@"yher_tableViewDidSelectRowAtIndexPath"
);
if
(
class_addMethod
(
class
,
originMethodSEL
,
(
IMP
)
yher_tableViewDidSelectRowAtIndexPath
,
"v@:@@"
))
{
Method
dis_swizzledMethod
=
class_getInstanceMethod
(
class
,
swizzledMethodSEL
);
//若子类实现了swizzledMethodSEL,直接exchange;
//若子类没有实现时,读取父类的方法实现,再添加到子类上,
//如果添加成功,exchange实现,否则不交换
BOOL
isLocal
=
[[
self
class
]
isLocallyDefinedMethod
:
dis_swizzledMethod
onClass
:
class
];
if
(
isLocal
)
{
Method
dis_originMethod
=
class_getInstanceMethod
(
class
,
originMethodSEL
);
method_exchangeImplementations
(
dis_originMethod
,
dis_swizzledMethod
);
}
else
{
if
(
class_addMethod
(
class
,
swizzledMethodSEL
,
class_getMethodImplementation
(
class
,
swizzledMethodSEL
),
method_getTypeEncoding
(
class_getInstanceMethod
(
class
,
swizzledMethodSEL
))))
{
dis_swizzledMethod
=
class_getInstanceMethod
(
class
,
swizzledMethodSEL
);
Method
dis_originMethod
=
class_getInstanceMethod
(
class
,
originMethodSEL
);
method_exchangeImplementations
(
dis_originMethod
,
dis_swizzledMethod
);
}
}
SEL
swizzleMethodSEL
=
NSSelectorFromString
(
@"yher_tableViewDidSelectRowAtIndexPath"
);
Method
originMethod
=
class_getInstanceMethod
(
delegateClass
,
originMethodSEL
);
Class
class
=
GetSelectorInsClass
(
delegateClass
,
originMethodSEL
,
originMethod
);
if
(
class_addMethod
(
class
,
swizzleMethodSEL
,
(
IMP
)
yher_tableViewDidSelectRowAtIndexPath
,
"v@:@@"
))
{
Method
swizzleMethod
=
class_getInstanceMethod
(
class
,
swizzleMethodSEL
);
method_exchangeImplementations
(
originMethod
,
swizzleMethod
);
}
}
@catch
(
NSException
*
exception
)
{
...
...
@@ -151,4 +138,16 @@ void yher_tableViewDidSelectRowAtIndexPath(id self, SEL _cmd, id tableView, NSIn
}
}
Class
GetSelectorInsClass
(
Class
hclass
,
SEL
sel
,
Method
sel_method
)
{
Class
super_class
=
[
hclass
superclass
];
if
(
!
super_class
)
{
return
hclass
;
}
Method
method
=
class_getInstanceMethod
(
super_class
,
sel
);
if
(
method
!=
sel_method
)
{
return
hclass
;
}
return
GetSelectorInsClass
(
super_class
,
sel
,
sel_method
);
}
@end
...
...
Please
register
or
login
to post a comment