https://blog.csdn.net/science_Lee/article/details/102488623

uitableview header 代码
- (void)createViews {
    [self addSubview:self.scrollImage];
    [self.scrollImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.equalTo(self);
//        make.height.mas_equalTo(500);
    }];

    [self addSubview:self.videoView];
    [self.videoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.equalTo(self);
    }];

    _contentLabel = [UILabel new];
    _contentLabel.font = [UIFont systemFontOfSize:14.f weight:UIFontWeightMedium];
    _contentLabel.textColor = hexColorStr(@"#222222");
    _contentLabel.numberOfLines = 0;
    _contentLabel.text = @"新疆 这个美好名词!从我读高中时就一直在我脑瓜子里出现!最早是在电视一个纪录片里看到,一大片望不到头的草原,数不过来的牛羊马悠闲的吃着嫩草,加上蓝天白云配上很有磁性的旁白!";
    [self addSubview:_contentLabel];
    [_contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(15);
        make.right.equalTo(self).offset(-15);
    }];

    [self addSubview:self.bottomView];
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self);
        make.top.equalTo(_contentLabel.mas_bottom).offset(10);
        make.height.mas_equalTo(94);
    }];

    [self mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.bottomView);
        make.width.mas_equalTo(LMScreenWidth());
    }];


    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getNotifyFromStatusDetail:) name:kStatusDetailLikeUnLikeNotify object:nil];
}
//
//  StatusDetailView.m
//  neighborhood
//
//  Created by wangtao on 2022/3/2.
//

#import "StatusDetailView.h"
#import "LMCommonTool.h"
#import "StatusDetailViewTopView.h"
#import <MJRefresh.h>
#import "LMMacros.h"
#import "StatusDetailHeaderView.h"
#import "StatusDetailCommentCell.h"
//#import <WTKit.h>
#import "StatusDetailBottomToolView.h"
#import "StatusDetailViewModel.h"


@interface StatusDetailView()<UITableViewDelegate, UITableViewDataSource, StatusDetailCommentCellDelegate>
@property (nonatomic, strong) StatusDetailViewTopView *topView;
@property (nonatomic, strong) UITableView *contentTableView;
@property (nonatomic, strong) StatusDetailHeaderView *headerView;
@property (nonatomic, strong) UIView *footerView;
@property (nonatomic, strong) StatusDetailBottomToolView *bottomToolView;
@property (nonatomic, strong) NSArray *comments;
/// 底部查看全部评论数量
@property (nonatomic, strong) UILabel *commentCountLabel;
@end

@implementation StatusDetailView
- (StatusDetailViewModel *)realVm {
    return (StatusDetailViewModel *)self.model;
}
- (instancetype)initWithFrame:(CGRect)frame
                   controller:(LMBaseViewController *)controller
                    viewModel:(nullable LMBaseViewModel *)viewModel{
    self.controller = controller;
    self.model = viewModel;
    if (self == [super initWithFrame:frame]) {

        [self createViews];
        [self addSubview:self.bottomToolView];
        [self.bottomToolView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(self);
            make.height.mas_equalTo(NavigationHeight());
        }];
        __weak typeof(self) _self = self;
        self.requestBlock = ^(NSArray * _Nullable response, NSArray * _Nullable currentResponse) {

            __strong typeof(_self) self = _self;
            [self endRefreshingWithCount:currentResponse.count];
            self.comments = response;
        };

        [self contentTableView];
    }
    return self;
}

- (void)createViews {

    __weak typeof(self) _self = self;
    [[self realVm] getStatusDetail:^(StatusDetailRespModel * _Nonnull resp) {
        __strong typeof(_self) self = _self;
        self.headerView.detail = resp;
        self.topView.detail = resp;
        self.bottomToolView.detail = resp;
        [self.contentTableView reloadData];
        self.commentCountLabel.text = [NSString stringWithFormat:@"查看全部%@条评论", resp.comment];
    }];

    self.backgroundColor = [UIColor blackColor];

    [self addSubview:self.topView];
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(self);
        make.height.mas_equalTo(StatBarHeight() + 68);
    }];
}

- (void)_retryGetData {
    //    [_controller hideNotifyView];
    //    [self reloadData];
}
- (void)_footerRefresh {
    [_contentTableView.mj_footer resetNoMoreData];
    if (self.beginRefreshBlock) self.beginRefreshBlock(NO);
}
- (void)_headerRefresh {
    if (self.beginRefreshBlock) self.beginRefreshBlock(YES);
}
- (void)endRefreshingWithCount:(NSInteger)count {

    _contentTableView.mj_header.isRefreshing ? [_contentTableView.mj_header endRefreshing] : nil;
    _contentTableView.mj_footer.isRefreshing ? [_contentTableView.mj_footer endRefreshing] : nil;

    if (count != kLMDefaultPageSize) {
        [_contentTableView.mj_footer endRefreshingWithNoMoreData];

    }
}
#pragma mark setter & getter
- (void)setComments:(NSArray *)comments {
    _comments = comments;
    if (_comments.count == 0) {
//        self.contentTableView.hidden = YES;
//        [[self realController] showEmptyDataView];
    } else {
//        self.contentTableView.hidden = NO;
//        [self.controller hideNotifyView];
    }
    [self.contentTableView reloadData];
}

- (StatusDetailBottomToolView *)bottomToolView {
    if (!_bottomToolView) {
        _bottomToolView = [StatusDetailBottomToolView new];
        _bottomToolView.statusId = [self realVm].statusId;
        __weak typeof(self) _self = self;
        _bottomToolView.didAddCommentToStatus = ^(StatusDetailComment * _Nonnull comment) {
            if (!comment) return;
            __strong typeof(_self) self = _self;
            NSMutableArray *tmp = [NSMutableArray arrayWithArray:self.comments];
            [tmp insertObject:comment atIndex:0];
            self.comments = tmp;
        };
    }
    return _bottomToolView;
}

- (StatusDetailHeaderView *)headerView {
    if (!_headerView) {
        _headerView = [[StatusDetailHeaderView alloc] initWithFrame:CGRectMake(0, 0, LMScreenWidth(), 0)];
    }
    return _headerView;
}

- (UIView *)footerView {
    if (!_footerView) {
        _footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, LMScreenWidth(), 60)];
        UIView *line = [UIView new];
        line.backgroundColor = hexColorStr(@"#E2E3E4");
        [_footerView addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_footerView).offset(15);
            make.left.equalTo(_footerView).offset(15);
            make.right.equalTo(_footerView).offset(-15);
            make.height.mas_equalTo(0.5);
        }];

        UILabel *titleLabel = [UILabel new];
        titleLabel.font = [UIFont systemFontOfSize:14.f weight:UIFontWeightMedium];
        titleLabel.textColor = hexColorStr(@"#222222");
        [_footerView addSubview:titleLabel];
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(_footerView);
            make.top.equalTo(line.mas_bottom).offset(15);
        }];
        _commentCountLabel = titleLabel;
    }
    return _footerView;
}

- (UITableView *)contentTableView {
    if (!_contentTableView) {
        _contentTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        _contentTableView.tableHeaderView = self.headerView;
        _contentTableView.tableFooterView = self.footerView;
        _contentTableView.dataSource = self;
        _contentTableView.delegate = self;
        _contentTableView.separatorInset = UIEdgeInsetsZero;
        _contentTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _contentTableView.backgroundColor = [UIColor whiteColor];
        _contentTableView.allowsMultipleSelection = NO;
        _contentTableView.allowsSelectionDuringEditing = NO;
        _contentTableView.allowsMultipleSelectionDuringEditing = NO;
        [self addSubview:_contentTableView];
        [_contentTableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.topView.mas_bottom);
            make.left.right.equalTo(self);
            make.bottom.equalTo(self.bottomToolView.mas_top);
        }];
        self.contentTableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(_headerRefresh)];
        self.contentTableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(_footerRefresh)];
        [self.contentTableView.mj_header beginRefreshing];
    }
    return _contentTableView;;
}

#pragma mark UITableViewDataSource 数据代理方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _comments.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    StatusDetailCommentCell *cell = [StatusDetailCommentCell cellWithTableView:tableView];
    cell.delegate = self;
    cell.indexPath = indexPath;
    cell.comment = [_comments objectAtIndex:indexPath.row];
    cell.bottomTool = self.bottomToolView;
    cell.statusId = [self realVm].statusId;
     return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

}

- (StatusDetailViewTopView *)topView {
    if (!_topView) {
        _topView = [StatusDetailViewTopView new];
        _topView.backgroundColor = [UIColor whiteColor];


    }
    return _topView;
}
- (void)_clickBackNavBtn {
    [[LMCommonTool topNav] popViewControllerAnimated:YES];
}

#pragma mark StatusDetailCommentCell
- (void)reloadCell:(StatusDetailCommentCell *)cell {
    NSLog(@"展开评论");
    [self.contentTableView beginUpdates];
    [self.contentTableView endUpdates];
}

@end

0 Comments latest

No comments.