This commit is contained in:
2026-01-28 16:35:47 +08:00
parent 22f77d56ea
commit b4db79eba8
23 changed files with 1185 additions and 0 deletions

View 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