#import "Uitableview+swizzle.h"
#import <UIKit/UIKit.h>
#import <objc/objc.h>
#import <objc/runtime.h>
@implementation UITableView (Swizzle)
Implementation: One-time set TableView location
+ (void) load
{
Static dispatch_once_t Oncetoken;
Dispatch_once (&oncetoken, ^{
[Self Swizzleinstancemethod: @selector (initwithframe:style:) Withnewmethod: @selector (yq_initwithframe:style:)];// Here to replace
});
}
-(Instancetype) Yq_initwithframe: (CGRect) Frame style: (Uitableviewstyle) style
{
UITableView *tableview = [self yq_initwithframe:frame style:style];
[TableView Setseparatorstyle:uitableviewcellseparatorstylenone];
return tableView;
}
/**
* Replace instance method (object method)
*
* @param Originalsel Original Method sel
* @param Newsel New Method sel
*/
+ (BOOL) Swizzleinstancemethod: (SEL) Originalsel Withnewmethod: (SEL) Newsel
{
Method Originalmethod = Class_getinstancemethod (self, originalsel);
Method Newmethod = Class_getinstancemethod (self, newsel);
if (!originalmethod | |!newmethod) return NO;
Class_addmethod (self, Originalsel, class_getmethodimplementation (self, Originalsel), method_gettypeencoding ( Originalmethod));
Class_addmethod (self, Newsel, class_getmethodimplementation (self, Newsel), method_gettypeencoding ( Newmethod));
Method_exchangeimplementations (Class_getinstancemethod (self, Originalsel), class_getinstancemethod (self, Newsel));
return YES;
}
Tableviewcell_swizzle
#import "Uitableviewcell+swizzle.h"
@implementation UITableViewCell (Swizzle)
+ (void) load
{
Static dispatch_once_t Oncetoken;
Dispatch_once (&oncetoken, ^{
[Self Swizzleclassmethod: @selector (initwithstyle:reuseidentifier:) Withnewmethod: @selector (yq_initwithstyle: Reuseidentifier:)];
});
}
-(Instancetype) Yq_initwithstyle: (Uitableviewcellstyle) style Reuseidentifier: (NSString *) reuseidentifier
{
UITableViewCell *cell = [self Yq_initwithstyle:style reuseidentifier:reuseidentifier];
[Cell Setselectionstyle:uitableviewcellselectionstylenone];
return cell;
}
@end
Custom-->tableview_swizzle