Files
keyboard/keyBoard/Class/AiTalk/VC/KBAIMessageListVC.m
2026-01-28 19:31:27 +08:00

152 lines
4.8 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// 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 clearColor];
/// 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)) {
//
// NSLog(@"[KBAIMessageListVC] trailingSwipeActionsConfigurationForRowAtIndexPath called for row: %ld", (long)indexPath.row);
//
// __weak typeof(self) weakSelf = self;
//
// // 删除按钮
// UIContextualAction *deleteAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive
// title:nil
// handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
// NSLog(@"[KBAIMessageListVC] Delete action triggered for row: %ld", (long)indexPath.row);
// [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 {
// NSLog(@"[KBAIMessageListVC] canEditRowAtIndexPath called for row: %ld", (long)indexPath.row);
// return YES;
//}
//- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
// NSLog(@"[KBAIMessageListVC] editingStyleForRowAtIndexPath called for row: %ld", (long)indexPath.row);
// return UITableViewCellEditingStyleDelete;
//}
#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 clearColor];
_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