2026-01-28 16:35:47 +08:00
|
|
|
|
//
|
|
|
|
|
|
// 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];
|
2026-01-28 19:31:27 +08:00
|
|
|
|
self.view.backgroundColor = [UIColor clearColor];
|
2026-01-28 16:35:47 +08:00
|
|
|
|
|
|
|
|
|
|
/// 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];
|
|
|
|
|
|
// 子类处理点击事件
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// 左滑删除
|
2026-01-28 18:11:46 +08:00
|
|
|
|
//- (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;
|
|
|
|
|
|
//}
|
2026-01-28 16:35:47 +08:00
|
|
|
|
|
|
|
|
|
|
#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;
|
2026-01-28 19:31:27 +08:00
|
|
|
|
_tableView.backgroundColor = [UIColor clearColor];
|
2026-01-28 16:35:47 +08:00
|
|
|
|
_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
|