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(@"=========");
}

DZNEmptyDataSet 使用的更多相关文章

  1. DZNEmptyDataSet,优秀的空白页或者出错页封装

    简介 项目主页:https://github.com/dzenbot/DZNEmptyDataSet 提示:主要用于UITableView和UICollectionView,也可以用于UIScroll ...

  2. DZNEmptyDataSet框架简介

    给大家推荐一个设置页面加载失败时显示加载失败等的框架. 下载地址:DZNEmptyDataSet https://github.com/dzenbot/DZNEmptyDataSet 上效果首先在你的 ...

  3. DZNEmptyDataSet——空白数据集显示框架

    GitHub地址:DZNEmptyDataSet DZNEmptyDataSet DZNEmptyDataSet 是基于 UITableView/UICollectionView 的范畴/扩展(cat ...

  4. DZNEmptyDataSet框架阅读

      前段时间使用公司封装的空白页占位视图工具,工具是对DZNEmptyDataSet框架的封装.这个框架以前在许多项目也都用过,却没有认真阅读过源码,真的很遗憾.这两天趁五一放假有空,将DZNEmpt ...

  5. DZNEmptyDataSet的使用

    DZNEmptyDataSet是外国友人写的开源项目,github地址(具体的使用以及Demo,点击进入github主页),简单介绍下DZNEmptyDataSet的使用方法. 对于iOS开发者来说, ...

  6. iOS比较常用的第三方及实例(不断更新中)

    把平时看到或项目用到的一些插件进行整理,文章后面分享一些不错的实例,若你有其它的插件欢迎分享,不断的进行更新: 一:第三方插件 1:基于响应式编程思想的oc 地址:https://github.com ...

  7. IOS比较常用的第三方组件及应用源代码(持续更新中)

    把平时看到或项目用到的一些插件进行整理,文章后面分享一些不错的实例,若你有其它的插件欢迎分享,不断的进行更新~ 一:第三方插件 1:基于响应式编程思想的oc 地址:https://github.com ...

  8. ios项目里扒出来的json文件

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo; color: #000000 } p.p2 { margin: 0.0px 0. ...

  9. iOS 常用第三方类库、完整APP示例

    一.第三方类库 1:基于响应式编程思想的oc地址:https://github.com/ReactiveCocoa/ReactiveCocoa2:hud提示框地址:https://github.com ...

随机推荐

  1. unity3d游戏开发学习分享之表面着色器讲解

    一.三种着色器的书写格式: 1.surface shaders, 指的是表面着色器 2.vertex and fragment shaders and 指的是顶点和片段着色器 3.fixed func ...

  2. dedecms的arclist循环中判断第一个li添加css,否则不加

    dedecms的arclist循环中,判断如果是第一个li,则添加固定的css,否则不加   写法如下: {dede:arclist row=4 flag='p'} <li [field:glo ...

  3. motion移植

    一. 支持ffmpeg功能(使能motion中的视频编码功能)支持视频采集 —> ffmpeg不支持 —host   1. mkdir _install 2. ./configure —pref ...

  4. 2014年王道论坛研究生机试练习赛(二)set 2 货币问题

    题目描述: 已知有面值为1元,2元,5元,10元,20元,50元,100元的货币若干(可认为无穷多),需支付价格为x的物品,并需要恰好支付,即没有找零产生.求,至少需要几张货币才能完成支付.如,若支付 ...

  5. Extjs学习笔记--(二)

    1.配置实用Extjs <link href="Extjs/resources/css/ext-all.css" rel="stylesheet" /&g ...

  6. Python 爬虫知识点 - 淘宝商品检索结果抓包分析

    一.抓包基础 在淘宝上搜索“Python机器学习”之后,试图抓取书名.作者.图片.价格.地址.出版社.书店等信息,查看源码发现html-body中没有这些信息,分析脚本发现,数据存储在了g_page_ ...

  7. PHP-004

    'URL_CASE_INSENSITIVE'  =>  true,设置为true的时候表示URL地址不区分大小写,这个也是框架在部署模式下面的默认设置. URL模式 : URL_MODEL设置 ...

  8. php第二例

    参考: http://www.php.cn/code/3645.html 前言 由于navicat在linux平台不能很好的支持, PHP的学习转到windows平台. php IDE: PhpSto ...

  9. poj_1988 并查集

    题目大意 开始有N堆砖块,编号为1,2....N,每堆都只有一个.之后可以进行两种操作: (1)M X Y 将编号为X的砖块所在的那堆砖拿起来放到编号为Y的砖块所在的堆上: (2)C X 查询编号为X ...

  10. 解决Chrome关联Html文件图标显示为空白

    用记事本保存为ChromeHTML.reg Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\CLSID\{42042206-2D85-1 ...