iOS空页面 DZNEmptyDataSet
2016-01-18 15:51
676 查看
android开发的时候,ListView 的empty处理得心应手,以为iOS开发 UITableView 处理empty 同样简单,事实证明,有了GitHub上的这篇文章,证明我的想法很是没错的。
Github地址:https://github.com/dzenbot/DZNEmptyDataSet
Github对这个功能有点喝集成已经说的很清楚了
我做个简单翻译
2,优点
Empty Data Sets are helpful for:
Avoiding white-screens and communicating to your users why the screen is empty.
避免tableview没数据的时候只显示白屏,用户会感激茫然
Calling to action (particularly as an onboarding process).
可以提高操作、交互性
Avoiding other interruptive mechanisms like showing error alerts.
避免tableview没数据的时候用alert这一类的提示强行打断用户的操作
Beeing consistent and improving the user experience.
一致、连贯行好,并且提升用户体验
Delivering a brand presence.
可以更好的展现出你的品牌
2,先看效果在决定用不用
3,集成
visit
CocoaPods' auto-generated doc http://cocoadocs.org/docsets/DZNEmptyDataSet/1.6.1
1,从下载的demo中拷贝这两个原文件到你的项目里
UIScrollView+EmptyDataSet.h
UIScrollView+EmptyDataSet.m
2,需要显示empty的table做如下处理
好累,不翻译了
The image for the empty state:
The attributed string for the title of the empty state:
The attributed string for the description of the empty state:
The attributed string to be used for the specified button state:
or the image to be used for the specified button state:
The background color for the empty state:
If you need a more complex layout, you can return a custom view instead:
Additionally, you can modify the horizontal and/or vertical alignments (as when using a tableHeaderView):
Delegate
Return the behaviours you would expect from the empty states, and receive the user events.
Asks to know if the empty state should be rendered and displayed (Default is YES) :
Asks for interaction permission (Default is YES) :
Asks for scrolling permission (Default is NO) :
Notifies when the dataset view was tapped:
Notifies when the data set call to action button was tapped:
Refresh
If you need to refresh the empty state layout, simply call:
or
depending of which you are using.
Force
You can also call
This might be useful if you have a lot of logic on your data source that you want to avoid calling, when not needed.
UIScrollView.
Github地址:https://github.com/dzenbot/DZNEmptyDataSet
Github对这个功能有点喝集成已经说的很清楚了
我做个简单翻译
2,优点
Empty Data Sets are helpful for:
Avoiding white-screens and communicating to your users why the screen is empty.
避免tableview没数据的时候只显示白屏,用户会感激茫然
Calling to action (particularly as an onboarding process).
可以提高操作、交互性
Avoiding other interruptive mechanisms like showing error alerts.
避免tableview没数据的时候用alert这一类的提示强行打断用户的操作
Beeing consistent and improving the user experience.
一致、连贯行好,并且提升用户体验
Delivering a brand presence.
可以更好的展现出你的品牌
2,先看效果在决定用不用
3,集成
visit
CocoaPods' auto-generated doc http://cocoadocs.org/docsets/DZNEmptyDataSet/1.6.1
1,从下载的demo中拷贝这两个原文件到你的项目里
UIScrollView+EmptyDataSet.h
UIScrollView+EmptyDataSet.m
2,需要显示empty的table做如下处理
@interface MainViewController : UITableViewController <DZNEmptyDataSetSource, DZNEmptyDataSetDelegate> - (void)viewDidLoad { [super viewDidLoad]; self.tableView.emptyDataSetSource = self; self.tableView.emptyDataSetDelegate = self; // A little trick for removing the cell separators self.tableView.tableFooterView = [UIView new]; }
好累,不翻译了
Data Source Implementation
Return the content you want to show on the empty state, and take advantage of NSAttributedString features to customise the text appearance.The image for the empty state:
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView { return [UIImage imageNamed:@"empty_placeholder"]; }
The attributed string for the title of the empty state:
- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView { NSString *text = @"Please Allow Photo Access"; NSDictionary *attributes = @{NSFontAttributeName: [UIFont boldSystemFontOfSize:18.0], NSForegroundColorAttributeName: [UIColor darkGrayColor]}; return [[NSAttributedString alloc] initWithString:text attributes:attributes]; }
The attributed string for the description of the empty state:
- (NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView *)scrollView { NSString *text = @"This allows you to share photos from your library and save photos to your camera roll."; NSMutableParagraphStyle *paragraph = [NSMutableParagraphStyle new]; paragraph.lineBreakMode = NSLineBreakByWordWrapping; paragraph.alignment = NSTextAlignmentCenter; NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:14.0], NSForegroundColorAttributeName: [UIColor lightGrayColor], NSParagraphStyleAttributeName: paragraph}; return [[NSAttributedString alloc] initWithString:text attributes:attributes]; }
The attributed string to be used for the specified button state:
- (NSAttributedString *)buttonTitleForEmptyDataSet:(UIScrollView *)scrollView forState:(UIControlState)state { NSDictionary *attributes = @{NSFontAttributeName: [UIFont boldSystemFontOfSize:17.0]}; return [[NSAttributedString alloc] initWithString:@"Continue" attributes:attributes]; }
or the image to be used for the specified button state:
- (UIImage *)buttonImageForEmptyDataSet:(UIScrollView *)scrollView forState:(UIControlState)state { return [UIImage imageNamed:@"button_image"]; }
The background color for the empty state:
- (UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView { return [UIColor whiteColor]; }
If you need a more complex layout, you can return a custom view instead:
- (UIView *)customViewForEmptyDataSet:(UIScrollView *)scrollView { UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; [activityView startAnimating]; return activityView; }
Additionally, you can modify the horizontal and/or vertical alignments (as when using a tableHeaderView):
- (CGPoint)offsetForEmptyDataSet:(UIScrollView *)scrollView { return CGPointMake(0, -self.tableView.tableHeaderView.frame.size.height/2); }
Delegate
Implementation
Return the behaviours you would expect from the empty states, and receive the user events.Asks to know if the empty state should be rendered and displayed (Default is YES) :
- (BOOL)emptyDataSetShouldDisplay:(UIScrollView *)scrollView { return YES; }
Asks for interaction permission (Default is YES) :
- (BOOL)emptyDataSetShouldAllowTouch:(UIScrollView *)scrollView { return YES; }
Asks for scrolling permission (Default is NO) :
- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView { return YES; }
Notifies when the dataset view was tapped:
- (void)emptyDataSetDidTapView:(UIScrollView *)scrollView { // Do something }
Notifies when the data set call to action button was tapped:
- (void)emptyDataSetDidTapButton:(UIScrollView *)scrollView { // Do something }
Refresh
layout
If you need to refresh the empty state layout, simply call:[self.tableView reloadData];
or
[self.collectionView reloadData];
depending of which you are using.
Force
layout update
You can also call [self.tableView reloadEmptyDataSet]to invalidate the current empty state layout and trigger a layout update, bypassing
-reloadData.
This might be useful if you have a lot of logic on your data source that you want to avoid calling, when not needed.
[self.tableView reloadEmptyDataSet]is the only way to refresh content when using with
UIScrollView.
相关文章推荐
- ios crash 日志分析
- iOS开发~CocoaPods使用详细说明
- IOS模拟动态图 大图和小图动态切换
- IOS-学习笔记(1)
- iOS9 提示框的使用
- IOS UserDefaults简介(一)
- iOS内存管理之@property属性详解
- iOS-内测-蒲公英应用内测使用
- 《ios与os x多线程和内存管理》
- ios 简单绘制
- iOS 多语言版本的开发
- 如何处理iOS中照片的方向
- ios耗时操作
- IOS处理位图
- iOS Runloop
- 百度云推送----iOS
- a valid provisioning profile for this executable was not found异常
- IOS多线程之NSThread
- iOS官方图标尺寸说明
- IOS 多线程之GCD