UITableView没数据时提示没有更多数据
来源:互联网 发布:上海 游戏程序员招聘 编辑:程序博客网 时间:2024/05/23 12:54
做项目的时候,用mj_footer提示没有更多数据,但是项目有筛选功能,进行筛选后,没有数据的情况下,是不会调用[_searchTableView.mj_footer endRefreshingWithNoMoreData];方法的;
解决办法:
由于项目多处用到了该功能,所以进行了封装(类扩展)。代码如下:
//.h文件
#import <UIKit/UIKit.h>
@interface UITableView (EmptyData)
/**tableView数据为空的时候进行提示*/
- (void)tableViewDisplayWithText:(NSString *)text ifNecessoryForRowCount:(NSUInteger)rowCount;
@end
//.m文件
#import "UITableView+EmptyData.h"
@implementation UITableView (EmptyData)
- (void)tableViewDisplayWithText:(NSString *)text ifNecessoryForRowCount:(NSUInteger)rowCount {
if (rowCount == 0) {
//没有数据的时候,UILabel的显示样式
UILabel *textLabel = [UILabel new];
textLabel.text = text;
textLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
textLabel.textColor = [UIColor lightGrayColor];
textLabel.textAlignment = NSTextAlignmentCenter;
[textLabel sizeToFit];
self.backgroundView = textLabel;
self.separatorStyle = UITableViewCellSeparatorStyleNone;
} else {
self.backgroundView = nil;
self.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
}
}
@end
然后倒入头文件,再调用就可以了,(由于自己项目中cell就一个section,所以没在section的方法里面写,如果是多个section,可以直接写在section代理方法中)
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSLog(@"数据数量--%ld",(long)self.dataArr.count);
[tableView tableViewDisplayWithText:@"没有查询到相对应的商品" ifNecessoryForRowCount:_dataArr.count];
return self.dataArr.count;
}
- UITableView没数据时提示没有更多数据
- UITableView没数据用户提示
- UITableView没数据时用户提示该怎么做?
- UITableView没数据时用户提示如何做?
- UITableView实现加载更多数据
- MJRefresh上拉加载没有更多数据不提示
- MUI列表中用到pullRefresh插件的上拉刷新,会存在第一次过滤数据或者查询数据如果没有结果时,没有提示“没有更多数据了”
- 亲,没有更多数据啦!
- UITableView 滑动自动加载更多数据
- UITableView 隐藏没有数据线条
- jsp页面没有刷新出来,提示我数据没匹配上
- iOS开发>>>UITableview实现更多数据显示方法
- easy-ui datagrid 没数据时候显示没有相关数据
- 使用MJRefresh时不能正常显示“没有更多数据”的bug
- iOS 开发单元格没有数据时显示提示文字
- UITableView中没有数据时,让其不显示下划线的两种方法
- iOS开发之UITableView数据为空的提示页面
- datagrid没有数据显示无数据提示信息
- ipython notebook使用
- Kinect for Windows SDK 1.8的改进及新特性
- hadoop编译问题(1)java.io.IOExc…
- hadoop编译问题(2)Could no…
- 关于MapReduce
- UITableView没数据时提示没有更多数据
- hadoop datanode启动不起来
- 同网段和不同网段设备通信原理详解
- python+Tornado + Supervisor + nginx部署
- Linux执行.sh文件,提示No su…
- history service 没有启…
- JDBC监听器-P6Spy
- Oracle导入dmp文件
- android存储之preference和SQLite