交换tableview reloadData 方法实现空数据提示
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Method oldMethod = class_getInstanceMethod(self, @selector(reloadData));
Method newMethod = class_getInstanceMethod(self, @selector(lz_reloadData));
method_exchangeImplementations(oldMethod, newMethod);
});
- (void)lj_reloadData {
[self lj_reloadData];
[self filColor];
}
- (void)filColor {
id<UITableViewDataSource> dataSource = self.dataSource;
NSInteger section = [dataSource respondsToSelector:@selector(numberOfSectionsInTableView:)] ? [dataSource respondsToSelector:@selector(numberOfSectionsInTableView:)] : 1;
NSInteger row = 0;
for (NSInteger i = 0; i < section; i++) {
row += [dataSource tableView:self numberOfRowsInSection:i];
}
if (row > 0) {
self.backgroundColor = [UIColor redColor];
}else {
self.backgroundColor = [UIColor whiteColor];
}
}
网友评论