runtime解決iOS11 tableview上移下移問(wèn)題
給tableview創(chuàng)建一個(gè)分類,然后交換初始化方法
#import "UITableView+Ex.h"
@implementation UITableView (Ex)
+(void)load{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
SEL originalSelector = @selector(initWithFrame:style:);
SEL swizzledSelector = @selector(mr_tableView_initWithFrame:style:);
Method originalMethod = class_getInstanceMethod([self class], originalSelector);
Method swizzledMethod = class_getInstanceMethod([self class], swizzledSelector);
BOOL didAddMethod = class_addMethod([self class], swizzledSelector,method_getImplementation(swizzledMethod) , method_getTypeEncoding(swizzledMethod));
if (didAddMethod)
{
class_replaceMethod([self class], swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod));
}
else
{
method_exchangeImplementations(originalMethod, swizzledMethod);
}
});
}
-(instancetype)mr_tableView_initWithFrame:(CGRect)frame style:(UITableViewStyle)style{
UITableView *tableview = [self mr_tableView_initWithFrame:frame style:style];
if (tableview) {
if (@available(iOS 11.0, *)) {
tableview.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
}
return tableview;
}
@end
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者