iOS

iOS - runtime方法交换之给reloadData添加头

2018-11-30  本文已影响31人  神灬渐入嘉靜

给TableView的reloadData方法添加调用前和调用后两个代理 并打印当前调用类

+ (void)load
{
    Method originalM = class_getInstanceMethod([self class], @selector(reloadData));
    Method exchangeM = class_getInstanceMethod([self class], @selector(reloadData_LPC));
    /** 交换方法 */
    method_exchangeImplementations(originalM, exchangeM);
}

- (void)reloadData_LPC
{
    [self reloadData_LPC];
}
- (void)reloadData_LPC
{
    NSLog(@"%s",__FUNCTION__);
    
    //reload前调用
    if (self.delegate_lpc && [self.delegate_lpc respondsToSelector:@selector(lpcTableViewBeforeReloadData)]) {
        [self.delegate_lpc lpcTableViewBeforeReloadData];
    }
    
    [super reloadData_LPC];
    
    //reload后调用
    if (self.delegate_lpc && [self.delegate_lpc respondsToSelector:@selector(lpcTableViewAfterReloadData)]) {
        [self.delegate_lpc lpcTableViewAfterReloadData];
    }
}
上一篇 下一篇

猜你喜欢

热点阅读