iOS 分类的应用(UITableView请求返回数据为空时展示页面)

分类模块代码:

#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];
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容