在开发过程中,我们经常会做到一些列表,当列表有数据的时候显示数据,而当列表没有数据或者网络错误的时候就显得空荡荡的,此时需要我们加上一个缺省页面,如头条:
我们的做法用到了UITableView的backgroundView属性
创建UITableView的category
@interface UITableView (LKCategory)
/**
根据count显示s提示信息(无数据,网络不可用,网络请求失败)
@param count 个数
*/
- (void)showDataCount:(NSInteger)count;
@end
@implementation UITableView (LKCategory)
- (void)showDataCount:(NSInteger)count{
if (count > 0) {
self.backgroundView = nil;
return;
}
UIView *backgroundView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.width, self.height)];
UIImageView *showImageView = [[UIImageView alloc]init];
showImageView.contentMode = UIViewContentModeScaleA