zoukankan      html  css  js  c++  java
  • DZNEmptyDataSet无数据占位图的使用,也可以使用DZNEmptyDataSet

    gitHub地址:https://github.com/dzenbot/DZNEmptyDataSet

    也可以使用DZNEmptyDataSet

    效果图:

    代码:

    #import "UIScrollView+EmptyDataSet.h"
    @interface DZNEmptyDataSetViewController ()<UITableViewDelegate,UITableViewDataSource,DZNEmptyDataSetSource,DZNEmptyDataSetDelegate>
    @property(nonatomic,strong)UITableView *tableView;
    @property(nonatomic,strong)NSMutableArray *dataArr;
    @end
    
    @implementation DZNEmptyDataSetViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        [self.view addSubview:self.tableView];
        
        self.tableView.delegate = self;
        self.tableView.dataSource = self;
        self.tableView.emptyDataSetSource = self;
        self.tableView.emptyDataSetDelegate = self;
        
        
          self.tableView.tableFooterView = [UIView new];
    
        [self.tableView registerClass:[UITableViewCell class]  forCellReuseIdentifier:@"cell"];
        
    }
    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
        return self.dataArr.count;
    }
    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
        cell.textLabel.text = self.dataArr[indexPath.row];
        return cell;
    }
    
    
    
    
    #pragma mark DZNEmptyDataSetSource,DZNEmptyDataSetDelegate
    //数据为空的时候添加图片提醒
    - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
    {
        return [UIImage imageNamed:@"ip_txt"];
    }
    //数据为空文字提醒
    - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
    {
        NSString *text = @"加载失败请重试";
        
        NSDictionary *attributes = @{NSFontAttributeName: [UIFont boldSystemFontOfSize:18.0f],
                                     NSForegroundColorAttributeName: [UIColor darkGrayColor]};
        
        return [[NSAttributedString alloc] initWithString:text attributes:attributes];
    }
    
    //数据为空的背景
    - (UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView
    {
        return [UIColor whiteColor];
    }
    
    
    //为空的时候添加一个风火轮
    /*
    - (UIView *)customViewForEmptyDataSet:(UIScrollView *)scrollView
    {
        UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
        [activityView startAnimating];
        return activityView;
    }
    */
    //如果tableveiw有tableHeaderView,可以自定义展示文字的位置
    - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView
    {
        return -self.tableView.tableHeaderView.frame.size.height/1.0f;
    }
    
    
    - (CGFloat)spaceHeightForEmptyDataSet:(UIScrollView *)scrollView
    {
        return 20.0f;
    }
    - (BOOL) emptyDataSetShouldAllowImageViewAnimate:(UIScrollView *)scrollView
    {
        return false;
    }
    - (void)emptyDataSet:(UIScrollView *)scrollView didTapView:(UIView *)view
    {
        [self.dataArr addObject:@"2"];
        [self.tableView reloadData];
        // Do something
    }
    
    
    
    
    -(UITableView *)tableView{
        if(!_tableView){
            _tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
        }
        return _tableView;
    }
    
    
    
    
    
    -(NSMutableArray *)dataArr{
        if(!_dataArr){
            _dataArr = [NSMutableArray array];
        }
        return _dataArr;
    }
    
    @end
    
    -(UIImage *)buttonBackgroundImageForEmptyDataSet:(UIScrollView *)scrollView forState:(UIControlState)state{
        return [UIImage imageNamed:@"ip_txt"];
    }
    
    - (void)emptyDataSet:(UIScrollView *)scrollView didTapButton:(UIButton *)button{
        NSLog(@"=========");
    }
    
  • 相关阅读:
    停止Java线程,小心interrupt()方法
    SLG手游Java服务器的设计与开发——架构分析
    大数据Hadoop核心架构HDFS+MapReduce+Hbase+Hive内部机理详解
    【转】阿里云主机购买使用教程
    使用 Apache MINA 开发高性能网络应用程序
    浅谈Java的Mina框架传递对象
    解析Mina代码三部曲
    java 子类继承父类 -- 重写、覆盖
    经度之战
    [USACO1.3]虫洞wormhole
  • 原文地址:https://www.cnblogs.com/hualuoshuijia/p/7230066.html
Copyright © 2011-2022 走看看