
主要变更: 1. 移除 UITableView,改为使用 EPMomentListView 以简化数据展示和交互。 2. 添加顶部固定文案 UILabel,提升用户体验。 3. 通过 EPMomentAPIHelper 统一管理 Moments 列表 API 请求,优化数据加载逻辑。 4. 更新 UI 约束,确保布局适配不同屏幕。 此重构旨在提升代码可维护性和用户界面的一致性。
135 lines
4.3 KiB
Objective-C
135 lines
4.3 KiB
Objective-C
//
|
||
// EPMomentViewController.m
|
||
// YuMi
|
||
//
|
||
// Created by AI on 2025-10-09.
|
||
// Copyright © 2025 YuMi. All rights reserved.
|
||
//
|
||
|
||
#import "EPMomentViewController.h"
|
||
#import <UIKit/UIKit.h>
|
||
#import <Masonry/Masonry.h>
|
||
#import "EPMomentCell.h"
|
||
#import "EPMomentListView.h"
|
||
|
||
@interface EPMomentViewController ()
|
||
|
||
// MARK: - UI Components
|
||
|
||
/// 列表视图(MVVM:View)
|
||
@property (nonatomic, strong) EPMomentListView *listView;
|
||
|
||
/// 顶部固定文案
|
||
@property (nonatomic, strong) UILabel *topTipLabel;
|
||
|
||
@end
|
||
|
||
@implementation EPMomentViewController
|
||
|
||
// MARK: - Lifecycle
|
||
|
||
- (void)viewDidLoad {
|
||
[super viewDidLoad];
|
||
|
||
self.title = @"动态";
|
||
|
||
[self setupUI];
|
||
[self.listView reloadFirstPage];
|
||
|
||
NSLog(@"[EPMomentViewController] 页面加载完成");
|
||
}
|
||
|
||
- (void)viewWillAppear:(BOOL)animated {
|
||
[super viewWillAppear:animated];
|
||
|
||
// 注意:当前 ViewController 没有包装在 NavigationController 中
|
||
// 如果未来需要导航栏,应该在 TabBarController 中包装 UINavigationController
|
||
}
|
||
|
||
// MARK: - Setup UI
|
||
|
||
- (void)setupUI {
|
||
// 先设置纯色背景作为兜底,避免白色闪烁
|
||
self.view.backgroundColor = [UIColor colorWithRed:0.95 green:0.95 blue:0.97 alpha:1.0];
|
||
|
||
UIImageView *bgImageView = [[UIImageView alloc] initWithImage:kImage(@"vc_bg")];
|
||
bgImageView.contentMode = UIViewContentModeScaleAspectFill;
|
||
bgImageView.clipsToBounds = YES;
|
||
[self.view addSubview:bgImageView];
|
||
[bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.edges.mas_equalTo(self.view);
|
||
}];
|
||
|
||
// 顶部固定文案
|
||
[self.view addSubview:self.topTipLabel];
|
||
[self.topTipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop).offset(8);
|
||
make.left.equalTo(self.view).offset(20);
|
||
make.right.equalTo(self.view).offset(-20);
|
||
}];
|
||
|
||
// 列表视图
|
||
[self.view addSubview:self.listView];
|
||
[self.listView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.left.right.bottom.equalTo(self.view);
|
||
make.top.equalTo(self.topTipLabel.mas_bottom).offset(8);
|
||
}];
|
||
|
||
// 右上角发布按钮
|
||
UIBarButtonItem *publishItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(onPublishButtonTapped)];
|
||
self.navigationItem.rightBarButtonItem = publishItem;
|
||
|
||
NSLog(@"[EPMomentViewController] UI 设置完成");
|
||
}
|
||
|
||
// 不再在 VC 内部直接发请求/维护分页
|
||
|
||
// MARK: - Actions
|
||
|
||
- (void)onPublishButtonTapped {
|
||
NSLog(@"[EPMomentViewController] 发布按钮点击");
|
||
// TODO: 跳转到发布页面
|
||
[self showAlertWithMessage:@"发布功能开发中"];
|
||
}
|
||
|
||
- (void)showAlertWithMessage:(NSString *)message {
|
||
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示"
|
||
message:message
|
||
preferredStyle:UIAlertControllerStyleAlert];
|
||
[alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]];
|
||
[self presentViewController:alert animated:YES completion:nil];
|
||
}
|
||
|
||
// 列表点击回调由 listView 暴露
|
||
|
||
// MARK: - Lazy Loading
|
||
|
||
// Lazy
|
||
|
||
- (EPMomentListView *)listView {
|
||
if (!_listView) {
|
||
_listView = [[EPMomentListView alloc] initWithFrame:CGRectZero];
|
||
__weak typeof(self) weakSelf = self;
|
||
_listView.onSelectMoment = ^(NSInteger index) {
|
||
__strong typeof(weakSelf) self = weakSelf;
|
||
[self showAlertWithMessage:[NSString stringWithFormat:@"点击了第 %ld 条动态", (long)index]];
|
||
};
|
||
}
|
||
return _listView;
|
||
}
|
||
|
||
- (UILabel *)topTipLabel {
|
||
if (!_topTipLabel) {
|
||
_topTipLabel = [UILabel new];
|
||
_topTipLabel.numberOfLines = 0;
|
||
_topTipLabel.textColor = [UIColor whiteColor];
|
||
_topTipLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightRegular];
|
||
_topTipLabel.text = @"The disease is like a cruel ruler, measuring the true length of my life, but it is also like a lamp, illuminating the present that I have always ignored. Now I feel a strange freedom: since the end is clear, I can take every step with my whole heart.";
|
||
}
|
||
return _topTipLabel;
|
||
}
|
||
|
||
// 无数据源属性
|
||
|
||
@end
|