202 lines
7.8 KiB
Mathematica
202 lines
7.8 KiB
Mathematica
![]() |
//
|
||
|
// RoomPublicScreenView.m
|
||
|
// DingDangApp
|
||
|
//
|
||
|
// Created by apple on 2023/5/27.
|
||
|
//
|
||
|
|
||
|
#import "RoomPublicMessageView.h"
|
||
|
#import "RoomPublicScreenTextCell.h"
|
||
|
#import "RoomPublicScreenCell.h"
|
||
|
#import "RoomPublicScreenEmojiCell.h"
|
||
|
#import "RoomPublicScreenGiftCell.h"
|
||
|
#import "RoomPublicScreenModel.h"
|
||
|
|
||
|
@interface RoomPublicMessageView () <UITableViewDelegate, UITableViewDataSource>
|
||
|
/**列表**/
|
||
|
@property (nonatomic, strong) UITableView *tableView;
|
||
|
@end
|
||
|
|
||
|
@implementation RoomPublicMessageView
|
||
|
- (instancetype)initWithFrame:(CGRect)frame {
|
||
|
self = [super initWithFrame:frame];
|
||
|
if (self) {
|
||
|
|
||
|
[self initWithSubView];
|
||
|
|
||
|
|
||
|
} return self;
|
||
|
}
|
||
|
|
||
|
- (void)initWithSubView {
|
||
|
|
||
|
[self addSubview:self.tableView];
|
||
|
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.right.top.bottom.equalTo(self).inset(0);
|
||
|
}];
|
||
|
}
|
||
|
|
||
|
- (void)refreshTableView {
|
||
|
|
||
|
[self.tableView reloadData];
|
||
|
if ([self.dataArr count] > 0) {
|
||
|
NSInteger toRow = self.dataArr.count - 1;
|
||
|
NSIndexPath *toIndexPath = [NSIndexPath indexPathForRow:toRow inSection:0];
|
||
|
NSInteger rows = [self.tableView numberOfRowsInSection:0];
|
||
|
if (toRow < rows) {
|
||
|
[self.tableView scrollToRowAtIndexPath:toIndexPath atScrollPosition:UITableViewScrollPositionBottom animated:NO];
|
||
|
}else{
|
||
|
NSLog(@"越界了。。。");
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#pragma mark --- UITableViewDelegate || UITableViewDataSource ---
|
||
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
||
|
|
||
|
return self.dataArr.count;
|
||
|
}
|
||
|
|
||
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
||
|
if (![ToolsObject IsNullWithObject:self.dataArr]) {
|
||
|
RoomPublicScreenModel *model;
|
||
|
if (indexPath.row < [self.dataArr count]) {
|
||
|
model = self.dataArr[indexPath.row];
|
||
|
if (!model) {
|
||
|
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
|
||
|
if (cell == nil) {
|
||
|
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"UITableViewCell"];
|
||
|
}
|
||
|
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
||
|
return cell;
|
||
|
}
|
||
|
|
||
|
|
||
|
if (model.msg_type == 1 ||
|
||
|
model.msg_type == 2 ||
|
||
|
model.msg_type == 6 ||
|
||
|
model.msg_type == 7 ) {//存文本消息
|
||
|
RoomPublicScreenTextCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RoomPublicScreenTextCell"];
|
||
|
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
||
|
|
||
|
if (indexPath.row < self.dataArr.count) {
|
||
|
cell.model = self.dataArr[indexPath.row];
|
||
|
WeakSelf(ws);
|
||
|
cell.cellTapGesActionBlock = ^(RoomUserInfoModel * _Nonnull userModel) {
|
||
|
if (ws.cellTapGesActionBlock) {
|
||
|
ws.cellTapGesActionBlock(userModel);
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
return cell;
|
||
|
}
|
||
|
if (model.msg_type == 3) {//聊天消息
|
||
|
RoomPublicScreenCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RoomPublicScreenCell"];
|
||
|
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
||
|
if (indexPath.row < self.dataArr.count) {
|
||
|
cell.model = self.dataArr[indexPath.row];
|
||
|
WeakSelf(ws);
|
||
|
cell.cellTapGesActionBlock = ^(RoomUserInfoModel * _Nonnull userModel) {
|
||
|
if (ws.cellTapGesActionBlock) {
|
||
|
ws.cellTapGesActionBlock(userModel);
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
return cell;
|
||
|
}
|
||
|
if (model.msg_type == 5) {//表情
|
||
|
RoomPublicScreenEmojiCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RoomPublicScreenEmojiCell"];
|
||
|
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
||
|
if (indexPath.row < self.dataArr.count) {
|
||
|
cell.model = self.dataArr[indexPath.row];
|
||
|
WeakSelf(ws);
|
||
|
cell.cellTapGesActionBlock = ^(RoomUserInfoModel * _Nonnull userModel) {
|
||
|
if (ws.cellTapGesActionBlock) {
|
||
|
ws.cellTapGesActionBlock(userModel);
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
return cell;
|
||
|
}
|
||
|
if (model.msg_type == 4 || model.msg_type == 8) {//抽奖礼物消息
|
||
|
RoomPublicScreenGiftCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RoomPublicScreenGiftCell"];
|
||
|
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
||
|
if (indexPath.row < self.dataArr.count) {
|
||
|
cell.model = self.dataArr[indexPath.row];
|
||
|
WeakSelf(ws);
|
||
|
cell.cellTapGesActionBlock = ^(RoomUserInfoModel * _Nonnull userModel) {
|
||
|
if (ws.cellTapGesActionBlock) {
|
||
|
ws.cellTapGesActionBlock(userModel);
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
return cell;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
|
||
|
if (cell == nil) {
|
||
|
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"UITableViewCell"];
|
||
|
}
|
||
|
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
||
|
return cell;
|
||
|
}
|
||
|
|
||
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
||
|
|
||
|
if (indexPath.row < [self.dataArr count]) {
|
||
|
RoomPublicScreenModel * model = self.dataArr[indexPath.row];
|
||
|
return model.cellH;
|
||
|
}else{
|
||
|
return CGFLOAT_MIN;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#pragma mark ------ 懒加载 ------
|
||
|
- (UITableView *)tableView {
|
||
|
if (!_tableView) {
|
||
|
_tableView = [UITableView new];
|
||
|
_tableView.backgroundColor = UIColor.clearColor;
|
||
|
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
||
|
_tableView.delaysContentTouches = NO;
|
||
|
_tableView.canCancelContentTouches = YES;
|
||
|
_tableView.estimatedRowHeight = 0;
|
||
|
_tableView.estimatedSectionHeaderHeight = 0;
|
||
|
_tableView.estimatedSectionFooterHeight = 0;
|
||
|
_tableView.showsVerticalScrollIndicator = NO;
|
||
|
_tableView.showsHorizontalScrollIndicator = NO;
|
||
|
if (@available(iOS 11.0, *)) {
|
||
|
_tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
|
||
|
}
|
||
|
_tableView.tableFooterView = [UIView new];
|
||
|
if (@available(iOS 15.0, *)) {
|
||
|
_tableView.sectionHeaderTopPadding = 0;
|
||
|
} else {
|
||
|
// Fallback on earlier versions
|
||
|
}
|
||
|
_tableView.delegate = self;
|
||
|
_tableView.dataSource = self;
|
||
|
[_tableView registerClass:NSClassFromString(@"RoomPublicScreenTextCell") forCellReuseIdentifier:@"RoomPublicScreenTextCell"];
|
||
|
[_tableView registerClass:NSClassFromString(@"RoomPublicScreenCell") forCellReuseIdentifier:@"RoomPublicScreenCell"];
|
||
|
[_tableView registerClass:NSClassFromString(@"RoomPublicScreenEmojiCell") forCellReuseIdentifier:@"RoomPublicScreenEmojiCell"];
|
||
|
[_tableView registerClass:NSClassFromString(@"RoomPublicScreenGiftCell") forCellReuseIdentifier:@"RoomPublicScreenGiftCell"];
|
||
|
|
||
|
} return _tableView;
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
// Only override drawRect: if you perform custom drawing.
|
||
|
// An empty implementation adversely affects performance during animation.
|
||
|
- (void)drawRect:(CGRect)rect {
|
||
|
// Drawing code
|
||
|
}
|
||
|
*/
|
||
|
|
||
|
@end
|