107 lines
3.8 KiB
Objective-C
107 lines
3.8 KiB
Objective-C
//
|
|
// QXToppicDynamicViewController.m
|
|
// QXLive
|
|
//
|
|
// Created by 启星 on 2025/6/3.
|
|
//
|
|
|
|
#import "QXToppicDynamicViewController.h"
|
|
#import "QXDynamicListCell.h"
|
|
#import "QXToppicDynamicTopView.h"
|
|
#import "QXDynamicNetwork.h"
|
|
|
|
@interface QXToppicDynamicViewController ()<UITableViewDelegate,UITableViewDataSource>
|
|
@property (strong, nonatomic) UITableView *tableView;
|
|
@property (strong, nonatomic) QXToppicDynamicTopView *topView;
|
|
@end
|
|
|
|
@implementation QXToppicDynamicViewController
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
// Do any additional setup after loading the view.
|
|
}
|
|
|
|
-(void)viewWillAppear:(BOOL)animated{
|
|
[super viewWillAppear:animated];
|
|
[self.navigationController setNavigationBarHidden:NO animated:YES];
|
|
}
|
|
|
|
-(void)setNavgationItems{
|
|
[super setNavgationItems];
|
|
self.navigationItem.title = self.model.title;
|
|
}
|
|
|
|
-(void)initSubViews{
|
|
self.page = 1;
|
|
self.tableView.tableHeaderView = self.topView;
|
|
[self.view addSubview:self.tableView];
|
|
[self getDynamicList];
|
|
}
|
|
-(void)getDynamicList{
|
|
MJWeakSelf
|
|
[QXDynamicNetwork topicDynamicListWithTopic_id:self.model.topic_id page:self.page successBlock:^(NSArray<QXDynamicModel *> * _Nonnull list) {
|
|
if (weakSelf.page == 1) {
|
|
[weakSelf.dataArray removeAllObjects];
|
|
}
|
|
[weakSelf.dataArray addObjectsFromArray:list];
|
|
[weakSelf.tableView.mj_header endRefreshing];
|
|
if (list.count == 0) {
|
|
weakSelf.tableView.mj_footer.state = MJRefreshStateNoMoreData;
|
|
}else{
|
|
[weakSelf.tableView.mj_footer endRefreshing];
|
|
}
|
|
[self.tableView reloadData];
|
|
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
|
[weakSelf.tableView.mj_header endRefreshing];
|
|
[weakSelf.tableView.mj_footer endRefreshing];
|
|
}];
|
|
}
|
|
#pragma mark - UITableViewDelegate,UITableViewDataSource
|
|
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
|
|
return self.dataArray.count;
|
|
}
|
|
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
|
|
QXDynamicListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"QXDynamicListCell" forIndexPath:indexPath];
|
|
cell.selectionStyle = NO;
|
|
cell.model = self.dataArray[indexPath.row];
|
|
// SPTrendListModel *model = self.dataArray[indexPath.row];
|
|
// cell.model = model;
|
|
MJWeakSelf
|
|
cell.onDeleteBlock = ^(QXDynamicModel * _Nonnull model) {
|
|
[weakSelf.dataArray removeObject:model];
|
|
[weakSelf.tableView reloadSection:indexPath.section withRowAnimation:(UITableViewRowAnimationAutomatic)];
|
|
};
|
|
return cell;
|
|
}
|
|
-(UITableView *)tableView{
|
|
if (!_tableView) {
|
|
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, NavContentHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavContentHeight) style:UITableViewStylePlain];
|
|
self.tableView.backgroundColor = [UIColor clearColor];
|
|
self.tableView.delegate = self;
|
|
self.tableView.dataSource = self;
|
|
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
|
[self.tableView registerNib:[UINib nibWithNibName:@"QXDynamicListCell" bundle:nil] forCellReuseIdentifier:@"QXDynamicListCell"];
|
|
self.tableView.rowHeight = UITableViewAutomaticDimension;
|
|
self.tableView.estimatedRowHeight = 152;
|
|
MJWeakSelf
|
|
_tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
|
|
weakSelf.page = 1;
|
|
[weakSelf getDynamicList];
|
|
}];
|
|
_tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
|
|
weakSelf.page++;
|
|
[weakSelf getDynamicList];
|
|
}];
|
|
}
|
|
return _tableView;
|
|
}
|
|
-(QXToppicDynamicTopView *)topView{
|
|
if (!_topView) {
|
|
_topView = [[QXToppicDynamicTopView alloc] initWithModel:self.model];
|
|
}
|
|
return _topView;
|
|
}
|
|
|
|
@end
|