2
This commit is contained in:
142
keyBoard/Class/AiTalk/VC/KBAIMessageListVC.m
Normal file
142
keyBoard/Class/AiTalk/VC/KBAIMessageListVC.m
Normal file
@@ -0,0 +1,142 @@
|
||||
//
|
||||
// KBAIMessageListVC.m
|
||||
// keyBoard
|
||||
//
|
||||
// Created by Mac on 2026/1/28.
|
||||
//
|
||||
|
||||
#import "KBAIMessageListVC.h"
|
||||
#import "KBAIMessageCell.h"
|
||||
#import <Masonry/Masonry.h>
|
||||
|
||||
@interface KBAIMessageListVC () <UITableViewDelegate, UITableViewDataSource>
|
||||
|
||||
@end
|
||||
|
||||
@implementation KBAIMessageListVC
|
||||
|
||||
#pragma mark - Lifecycle
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
self.view.backgroundColor = [UIColor whiteColor];
|
||||
|
||||
/// 1:控件初始化
|
||||
[self setupUI];
|
||||
|
||||
/// 2:加载数据
|
||||
[self loadData];
|
||||
}
|
||||
|
||||
#pragma mark - 1:控件初始化
|
||||
|
||||
- (void)setupUI {
|
||||
[self.view addSubview:self.tableView];
|
||||
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.edges.equalTo(self.view);
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark - 2:数据加载
|
||||
|
||||
- (void)loadData {
|
||||
// 子类重写
|
||||
}
|
||||
|
||||
- (void)deleteItemAtIndexPath:(NSIndexPath *)indexPath {
|
||||
// 子类重写
|
||||
}
|
||||
|
||||
#pragma mark - UITableViewDataSource
|
||||
|
||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
||||
return self.dataArray.count;
|
||||
}
|
||||
|
||||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
KBAIMessageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"KBAIMessageCell" forIndexPath:indexPath];
|
||||
cell.indexPath = indexPath;
|
||||
|
||||
// 子类配置数据
|
||||
if (indexPath.row < self.dataArray.count) {
|
||||
NSDictionary *item = self.dataArray[indexPath.row];
|
||||
[cell configWithAvatar:item[@"avatar"]
|
||||
name:item[@"name"]
|
||||
content:item[@"content"]
|
||||
time:item[@"time"]
|
||||
isPinned:[item[@"isPinned"] boolValue]];
|
||||
}
|
||||
|
||||
return cell;
|
||||
}
|
||||
|
||||
#pragma mark - UITableViewDelegate
|
||||
|
||||
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
return 76;
|
||||
}
|
||||
|
||||
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
||||
// 子类处理点击事件
|
||||
}
|
||||
|
||||
/// 左滑删除
|
||||
- (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath API_AVAILABLE(ios(11.0)) {
|
||||
|
||||
__weak typeof(self) weakSelf = self;
|
||||
|
||||
// 删除按钮
|
||||
UIContextualAction *deleteAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive
|
||||
title:nil
|
||||
handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
|
||||
[weakSelf deleteItemAtIndexPath:indexPath];
|
||||
completionHandler(YES);
|
||||
}];
|
||||
deleteAction.backgroundColor = [UIColor colorWithHex:0xF44336];
|
||||
if (@available(iOS 13.0, *)) {
|
||||
deleteAction.image = [UIImage systemImageNamed:@"trash.fill"];
|
||||
}
|
||||
|
||||
UISwipeActionsConfiguration *config = [UISwipeActionsConfiguration configurationWithActions:@[deleteAction]];
|
||||
config.performsFirstActionWithFullSwipe = NO;
|
||||
return config;
|
||||
}
|
||||
|
||||
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
return YES;
|
||||
}
|
||||
|
||||
#pragma mark - JXCategoryListContentViewDelegate
|
||||
|
||||
- (UIView *)listView {
|
||||
return self.view;
|
||||
}
|
||||
|
||||
#pragma mark - Lazy Load
|
||||
|
||||
- (UITableView *)tableView {
|
||||
if (!_tableView) {
|
||||
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
|
||||
_tableView.delegate = self;
|
||||
_tableView.dataSource = self;
|
||||
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
||||
_tableView.backgroundColor = [UIColor whiteColor];
|
||||
_tableView.showsVerticalScrollIndicator = NO;
|
||||
[_tableView registerClass:[KBAIMessageCell class] forCellReuseIdentifier:@"KBAIMessageCell"];
|
||||
|
||||
if (@available(iOS 15.0, *)) {
|
||||
_tableView.sectionHeaderTopPadding = 0;
|
||||
}
|
||||
}
|
||||
return _tableView;
|
||||
}
|
||||
|
||||
- (NSMutableArray *)dataArray {
|
||||
if (!_dataArray) {
|
||||
_dataArray = [NSMutableArray array];
|
||||
}
|
||||
return _dataArray;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user