// // ZCBaseTableVC.m // XLChat // // Created by 张灿 on 2017/10/24. // Copyright © 2017年 张灿. All rights reserved. // #import "ZCBaseTableVC.h" #import "UIScrollView+EmptyDataSet.h" @interface ZCBaseTableVC () @end @interface ZCBaseTableVC () @end @implementation ZCBaseTableVC - (void)viewDidLoad { [super viewDidLoad]; self.isShowEmptyData = YES; self.isAllowScroll = NO; self.tableView.emptyDataSetSource = self; self.tableView.emptyDataSetDelegate = self; } -(UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView { if (self.noDataImgName) { return [UIImage imageNamed:self.noDataImgName]; } return [UIImage new]/*[UIImage imageNamed:@"vqu_images_air_no"]*/; } - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView { NSString *text = self.noDataTitle?self.noDataTitle:@""/*@"暂无数据"*/; NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:14.0f], NSForegroundColorAttributeName: HexColorFromRGB(0x6C6B70)}; return [[NSAttributedString alloc] initWithString:text attributes:attributes]; } - (NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView *)scrollView { NSString *text = self.noDataDetailTitle; NSMutableParagraphStyle *paragraph = [NSMutableParagraphStyle new]; paragraph.lineBreakMode = NSLineBreakByWordWrapping; paragraph.alignment = NSTextAlignmentCenter; NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:17.0f], NSForegroundColorAttributeName: [UIColor lightGrayColor], NSParagraphStyleAttributeName: paragraph}; return self.noDataDetailTitle?[[NSAttributedString alloc] initWithString:text attributes:attributes]:nil; } - (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView{ return self.isAllowScroll; } - (BOOL)emptyDataSetShouldAllowTouch:(UIScrollView *)scrollView { return YES; } - (BOOL)emptyDataSetShouldDisplay:(UIScrollView *)scrollView { return self.isShowEmptyData; } - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView { // return (self.tableView.frame.size.height-50)/2-(self.tableView.frame.size.height-self.tableView.tableHeaderView.frame.size.height-50)/2; // if(self.tableView.tableHeaderView !=nil){ // return self.tableView.tableHeaderView.frame.size.height-(self.tableView.frame.size.height-50-50)/2;//有tableHeaderview的时候距离tableHeaderView为50,还有一个50代表实际的图片,文字按钮加间距的高度总和 // }else{ // return 0;//没有tableHeaderView的时候在中间显示 // } return 0; } - (NSAttributedString *)buttonTitleForEmptyDataSet:(UIScrollView *)scrollView forState:(UIControlState)state { NSDictionary *attributes = @{NSFontAttributeName: [UIFont boldSystemFontOfSize:16.0f]}; return self.btnTitle?[[NSAttributedString alloc] initWithString:self.btnTitle attributes:attributes]:nil; } - (UIImage *)buttonImageForEmptyDataSet:(UIScrollView *)scrollView forState:(UIControlState)state { return self.btnImgName?[UIImage imageNamed:self.btnImgName]:nil; } - (void)emptyDataSet:(UIScrollView *)scrollView didTapButton:(UIButton *)button { [self buttonEvent]; } - (nullable UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView{ return [UIColor clearColor]; } //解决和上下拉刷新控件一起显示时候的问题 - (void)emptyDataSetWillAppear:(UIScrollView *)scrollView { scrollView.contentOffset = CGPointZero; } - (void)emptyDataSetDidAppear:(UIScrollView *)scrollView{ scrollView.contentOffset = CGPointZero; } - (void)emptyDataSetWillDisappear:(UIScrollView *)scrollView{ scrollView.contentOffset = CGPointZero; } /// 下拉刷新回调方法,具体实现代码需要子类实现 - (void)headerRefreshing{ } /// 上拉加载回调方法,具体实现代码需要子类实现 - (void)footerRefreshing{ } #pragma mark 按钮事件 -(void)buttonEvent { } -(UITableView *)tableView { if(_tableView == nil) { _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, NavBarHeight,[[UIScreen mainScreen] bounds].size.width,[[UIScreen mainScreen] bounds].size.height-NavBarHeight) style:UITableViewStyleGrouped]; _tableView.backgroundColor = [UIColor clearColor]; _tableView.tableFooterView = [UIView new]; _tableView.tableHeaderView = [UIView new]; _tableView.showsVerticalScrollIndicator = NO; _tableView.showsHorizontalScrollIndicator = NO; _tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, CGFLOAT_MIN)]; if (@available(iOS 15.0, *)) { _tableView.sectionHeaderTopPadding = 0; } } return _tableView; } -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return 0.01f; } - (MJRefreshNormalHeader *)refreshHeader{ if(!_refreshHeader){ // 设置回调(一旦进入刷新状态,就调用target的action,也就是调用self的headerRefreshing方法) _refreshHeader = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(headerRefreshing)]; } return _refreshHeader; } - (MJRefreshAutoNormalFooter *)loadMoreFooter{ if(!_loadMoreFooter){ // 设置回调(一旦进入刷新状态,就调用target的action,也就是调用self的footerRefreshing方法) _loadMoreFooter = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(footerRefreshing)]; _loadMoreFooter.triggerAutomaticallyRefreshPercent = 0.1; } return _loadMoreFooter; } - (MJRefreshAutoNormalFooter *)noLoadMoreFooter{ if(!_noLoadMoreFooter){ _noLoadMoreFooter = [[MJRefreshAutoNormalFooter alloc]initWithFrame:CGRectZero]; _noLoadMoreFooter.backgroundColor = [UIColor clearColor]; _noLoadMoreFooter.state = MJRefreshStateIdle; _noLoadMoreFooter.mj_h = 0;//重新设置高度,不让看到它,并且当设置为table.footer时,table会自动调整自己的高度 _noLoadMoreFooter.clipsToBounds = YES;//不让看不到菊花 } return _noLoadMoreFooter; } @end