源码地址
config
导入头文件:#import <DZNEmptyDataSet/UIScrollView+EmptyDataSet.h>
继承:DZNEmptyDataSetSource,DZNEmptyDataSetDelegate
self.tableView.emptyDataSetSource = self;
self.tableView.emptyDataSetDelegate = self;
复制代码
e.g.:
#pragma mark: - DZNEmptyDataSetSource Methods
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
NSString *imageNameStr = @"common_wifi";
return [UIImage imageNamed: ([NetworkVerification verificationCurrentNetwork] == -1) ? imageNameStr : @"common_no_record"];
}
- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
NSString *text = @"暂无列表信息!";
if (([NetworkVerification verificationCurrentNetwork] == -1)) {
text = @"网络连接失败,请检查网络设置";
}
NSMutableParagraphStyle *paragraph = [NSMutableParagraphStyle new];
paragraph.lineBreakMode = NSLineBreakByWordWrapping;
paragraph.alignment = NSTextAlignmentCenter;
NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:13.0f],
NSForegroundColorAttributeName: [UIColor lightGrayColor],
NSParagraphStyleAttributeName: paragraph};
return [[NSAttributedString alloc] initWithString:text attributes:attributes];
}
- (NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView *)scrollView {
NSString *text = @" ";
if (([NetworkVerification verificationCurrentNetwork] == -1)) {
text = @"点击刷新";
}
NSMutableParagraphStyle *paragraph = [NSMutableParagraphStyle new];
paragraph.lineBreakMode = NSLineBreakByWordWrapping;
paragraph.alignment = NSTextAlignmentCenter;
NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:14.0f],
NSForegroundColorAttributeName: [UIColor lightGrayColor],
NSParagraphStyleAttributeName: paragraph};
return [[NSAttributedString alloc] initWithString:text attributes:attributes];
}
- (UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView {
return [Common hexStringToColor:@"#DEDEDE"];
}
- (CGFloat)spaceHeightForEmptyDataSet:(UIScrollView *)scrollView {
return 15;
}
#pragma mark: - DZNEmptyDataSetDelegate Methods
- (void)emptyDataSet:(UIScrollView *)scrollView didTapView:(UIView *)view {
// Do something
debugLog(@"dosomeThing");
//[self.tableView.mj_header beginRefreshing];
[self checkLocationCityName];
}
复制代码
遇到的问题:不显示出来
- 1.要遵守数据源和代理协议
- 2.要刷新
- 3.刷新完毕后,向上偏移了 解决办法
- (void)emptyDataSetWillAppear:(UIScrollView *)scrollView {
scrollView.contentOffset = CGPointZero;
}
复制代码