Files
real-e-party-iOS/YuMi/E-P/NewMoments/Views/EPMomentListView.m
edwinQQQ ceaeb5c951 feat: 添加 EPMomentPublishViewController 以支持图文发布功能
主要变更:
1. 新增 EPMomentPublishViewController.h 和 EPMomentPublishViewController.m 文件,提供图文发布页面的 UI 和逻辑。
2. 实现了发布按钮、文本输入框、图片选择功能,支持最多选择 9 张图片。
3. 集成了 TZImagePickerController 以便于用户选择图片。
4. 更新了 EPMomentViewController,添加了跳转到发布页面的逻辑。

此功能旨在提升用户体验,简化图文发布流程。
2025-10-10 19:06:06 +08:00

175 lines
5.8 KiB
Objective-C

//
// EPMomentListView.m
// YuMi
//
// Created by AI on 2025-10-10.
//
#import <UIKit/UIKit.h>
#import "EPMomentListView.h"
#import "EPMomentCell.h"
#import <MJRefresh/MJRefresh.h>
@interface EPMomentListView () <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UIRefreshControl *refreshControl;
@property (nonatomic, strong) NSMutableArray *mutableRawList;
@property (nonatomic, strong) EPMomentAPIHelper *api;
@property (nonatomic, assign) BOOL isLoading;
@property (nonatomic, copy) NSString *nextID;
@end
@implementation EPMomentListView
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor clearColor];
_api = [[EPMomentAPIHelper alloc] init];
_mutableRawList = [NSMutableArray array];
_sourceType = EPMomentListSourceTypeRecommend;
[self addSubview:self.tableView];
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self);
}];
}
return self;
}
- (NSArray<NSMutableDictionary *> *)rawList {
return [self.mutableRawList copy];
}
- (void)reloadFirstPage {
self.nextID = @"";
[self.mutableRawList removeAllObjects];
[self.tableView reloadData];
[self.tableView.mj_footer resetNoMoreData];
[self requestNextPage];
}
- (void)requestNextPage {
if (self.isLoading) return;
self.isLoading = YES;
@kWeakify(self);
[self.api fetchLatestMomentsWithNextID:self.nextID
completion:^(NSArray<MomentsInfoModel *> * _Nullable list, NSString * _Nonnull nextMomentID) {
@kStrongify(self);
[self endLoading];
if (list.count > 0) {
self.nextID = nextMomentID;
[self.mutableRawList addObjectsFromArray:list];
[self.tableView reloadData];
if (nextMomentID.length > 0) {
[self.tableView.mj_footer endRefreshing];
} else {
[self.tableView.mj_footer endRefreshingWithNoMoreData];
}
} else {
// TODO: 后续补充空数据页面
if (self.nextID.length == 0) {
[self.tableView.mj_footer endRefreshingWithNoMoreData];
} else {
[self.tableView.mj_footer endRefreshing];
}
}
} failure:^(NSInteger code, NSString * _Nullable msg) {
@kStrongify(self);
[self endLoading];
// TODO: 完全没有数据情况下,后续补充数据异常页面
[self.tableView.mj_footer endRefreshing];
}];
}
- (void)endLoading {
self.isLoading = NO;
[self.refreshControl endRefreshing];
}
#pragma mark - UITableView
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.mutableRawList.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
EPMomentCell *cell = [tableView dequeueReusableCellWithIdentifier:@"NewMomentCell" forIndexPath:indexPath];
if (indexPath.row < self.mutableRawList.count) {
MomentsInfoModel *model = [self.mutableRawList xpSafeObjectAtIndex:indexPath.row];
[cell configureWithModel:model];
}
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewAutomaticDimension;
}
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 200;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (self.onSelectMoment) self.onSelectMoment(indexPath.row);
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat offsetY = scrollView.contentOffset.y;
CGFloat contentHeight = scrollView.contentSize.height;
CGFloat screenHeight = scrollView.frame.size.height;
if (offsetY > contentHeight - screenHeight - 100 && !self.isLoading) {
[self requestNextPage];
}
}
#pragma mark - Lazy
- (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.estimatedRowHeight = 200;
_tableView.rowHeight = UITableViewAutomaticDimension;
_tableView.showsVerticalScrollIndicator = NO;
// 底部留出更高空间,避免被悬浮 TabBar 遮挡
_tableView.contentInset = UIEdgeInsetsMake(10, 0, 120, 0);
_tableView.scrollIndicatorInsets = UIEdgeInsetsMake(10, 0, 120, 0);
[_tableView registerClass:[EPMomentCell class] forCellReuseIdentifier:@"NewMomentCell"];
_tableView.refreshControl = self.refreshControl;
// MJRefresh Footer - 加载更多
__weak typeof(self) weakSelf = self;
_tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
__strong typeof(weakSelf) self = weakSelf;
if (!self.isLoading && self.nextID.length > 0) {
[self requestNextPage];
} else if (self.nextID.length == 0) {
[self.tableView.mj_footer endRefreshingWithNoMoreData];
} else {
[self.tableView.mj_footer endRefreshing];
}
}];
}
return _tableView;
}
- (UIRefreshControl *)refreshControl {
if (!_refreshControl) {
_refreshControl = [[UIRefreshControl alloc] init];
[_refreshControl addTarget:self action:@selector(reloadFirstPage) forControlEvents:UIControlEventValueChanged];
}
return _refreshControl;
}
@end