runtime解決iOS11 tableview上移下移問(wèn)題

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)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容

  • *面試心聲:其實(shí)這些題本人都沒(méi)怎么背,但是在上海 兩周半 面了大約10家 收到差不多3個(gè)offer,總結(jié)起來(lái)就是把...
    Dove_iOS閱讀 27,210評(píng)論 30 471
  • 設(shè)計(jì)模式是什么? 你知道哪些設(shè)計(jì)模式,并簡(jiǎn)要敘述? 設(shè)計(jì)模式是一種編碼經(jīng)驗(yàn),就是用比較成熟的邏輯去處理某一種類型的...
    琦均煞Sylar閱讀 428評(píng)論 0 0
  • 對(duì)于從事 iOS 開發(fā)人員來(lái)說(shuō),所有的人都會(huì)答出【runtime 是運(yùn)行時(shí)】什么情況下用runtime?大部分人能...
    夢(mèng)夜繁星閱讀 3,732評(píng)論 7 64
  • 學(xué)習(xí)力目前我還掌握的不夠好,《好好學(xué)習(xí)》這本書也正在看。 但因?yàn)槌醪接辛诉@個(gè)底層邏輯的認(rèn)知,我覺(jué)得就是一個(gè)很大的提...
    雲(yún)端生活美學(xué)閱讀 84評(píng)論 0 0