分类模块代码:
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface UITableView (category)
- (void)tableviewShowWithMessage:(NSString *)messsage forDataCount:(NSInteger)dataCount;
@end
#import "UITableView+category.h"
@implementation UITableView (category)
- (void)tableviewShowWithMessage:(NSString *)messsage forDataCount:(NSInteger)dataCount{
if (dataCount == 0) {
UIView *view = [UIView new];
UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Bitmap"]];
imgView.center = self.center;
[view addSubview:imgView];
UILabel *showLab = [UILabel new];
showLab.text = messsage;
showLab.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
showLab.textColor = [UIColor blackColor];
showLab.textAlignment = NSTextAlignmentCenter;
[showLab sizeToFit];
// 这块由于不想增加更多的代码(第三方、分类),showLab的Y值是根据图片的高度手动算的,需注意。
[showLab setFrame:CGRectMake(20, self.center.y+60, [UIScreen mainScreen].bounds.size.width-40, 20)];
[view addSubview:showLab];
self.backgroundView = view;
}else{
self.backgroundView = nil;
}
}
请求返回为空时调用:
[self.tableview tableviewShowWithMessage:@"暂无数据" forDataCount:self.dataArray.count];
[self.tableview reloadData];
网友评论