Files
yinmeng-ios/xplan-ios/Main/Mine/View/XPMineFansTeamViewController.m
2023-01-04 14:43:47 +08:00

134 lines
4.6 KiB
Objective-C

//
// XPMineFansTeamViewController.m
// xplan-ios
//
// Created by GreenLand on 2022/4/8.
//
#import "XPMineFansTeamViewController.h"
///Third
#import <Masonry/Masonry.h>
///Tool
#import "ThemeColor.h"
#import "NSArray+Safe.h"
///Model
#import "XPMineAnchorFansTeamModel.h"
///View
#import "XPMineAnchorFansTeamTableViewCell.h"
#import "XPMineVisitorEmptyTableViewCell.h"
///P
#import "XPMineFansTeamPresenter.h"
#import "XPMineAnchorFansTeamProtocol.h"
///VC
#import "XPMineUserInfoViewController.h"
#import "SessionViewController.h"
@interface XPMineFansTeamViewController ()<UITableViewDelegate,UITableViewDataSource, XPMineAnchorFansTeamProtocol>
///列表
@property (nonatomic,strong) UITableView *tableView;
///数据源
@property (nonatomic,strong) NSMutableArray *datasource;
///当前页数
@property (nonatomic,assign) int page;
///更多数据
@property (nonatomic,assign) BOOL hasNoMoreData;
@end
@implementation XPMineFansTeamViewController
- (XPMineFansTeamPresenter *)createPresenter {
return [[XPMineFansTeamPresenter alloc] init];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self initSubViews];
[self initSubViewConstraints];
[self.presenter getAnchorFansTeamList:self.page pageSize:100 state:0];
}
#pragma mark - Private Method
- (void)initSubViews {
self.title = @"我加入的粉丝团";
[self.view addSubview:self.tableView];
}
- (void)initSubViewConstraints {
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.view);
}];
}
#pragma mark - XPMineAnchorFansTeamProtocol
- (void)getAnchorFansTeamListSuccess:(NSArray *)array state:(int)state {
[self.datasource addObjectsFromArray:array];
[self.tableView reloadData];
}
- (void)getAnchorFansTeamListFail:(int)state {
[self.tableView reloadData];
}
#pragma mark - UITableViewDelegate And UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.datasource.count > 0 ? self.datasource.count : 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (self.datasource.count > 0) {
XPMineAnchorFansTeamTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPMineAnchorFansTeamTableViewCell class])];
if (cell == nil) {
cell = [[XPMineAnchorFansTeamTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPMineAnchorFansTeamTableViewCell class])];
}
cell.item = [self.datasource safeObjectAtIndex1:indexPath.row];
return cell;
}
XPMineVisitorEmptyTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPMineVisitorEmptyTableViewCell class])];
if (cell == nil) {
cell = [[XPMineVisitorEmptyTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPMineVisitorEmptyTableViewCell class])];
}
cell.emptyTitle = @"暂无粉丝团";
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
XPMineAnchorFansTeamModel *item = [self.datasource safeObjectAtIndex1:indexPath.row];
XPMineUserInfoViewController * userInfoVC = [[XPMineUserInfoViewController alloc] init];
userInfoVC.uid = item.teamUid;
[self.navigationController pushViewController:userInfoVC animated:YES];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return self.datasource.count > 0 ? 56 : 400;
}
#pragma mark - Getters And Setters
- (UITableView *)tableView {
if (!_tableView) {
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.tableFooterView = [UIView new];
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_tableView.backgroundColor = [UIColor clearColor];
_tableView.rowHeight = 56;
if (@available(iOS 11.0, *)) {
_tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
[_tableView registerClass:[XPMineVisitorEmptyTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPMineVisitorEmptyTableViewCell class])];
[_tableView registerClass:[XPMineAnchorFansTeamTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPMineAnchorFansTeamTableViewCell class])];
}
return _tableView;
}
- (NSMutableArray *)datasource {
if (!_datasource) {
_datasource = [NSMutableArray array];
}
return _datasource;
}
@end