3
This commit is contained in:
@@ -12,35 +12,55 @@
|
||||
|
||||
// 自定义卡片 Cell
|
||||
#import "HomeRankCardCell.h"
|
||||
#import "KBHomeVM.h"
|
||||
#import "KBCharacter.h"
|
||||
|
||||
@interface HomeRankContentVC ()
|
||||
@property (nonatomic, strong) NSArray<NSDictionary *> *dataSource; // 简单模拟数据
|
||||
@property (nonatomic, copy, nullable) NSString *tagId; // 当前标签 id
|
||||
@property (nonatomic, strong) KBHomeVM *homeVM;
|
||||
@property (nonatomic, strong) NSArray<KBCharacter *> *characters; // 当前标签下的角色列表
|
||||
@end
|
||||
|
||||
@implementation HomeRankContentVC
|
||||
|
||||
- (instancetype)initWithTagId:(NSString *)tagId {
|
||||
if (self = [super init]) {
|
||||
_tagId = [tagId copy];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)init {
|
||||
return [self initWithTagId:nil];
|
||||
}
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
|
||||
self.view.backgroundColor = COLOR_WITH_RGB(246/255.0, 253/255.0, 249/255.0, 1.0); // 淡绿色背景
|
||||
|
||||
// 数据
|
||||
self.dataSource = @[
|
||||
@{@"title":@"High EQ", @"desc":@"Be Neither Too Close\nNor Too Distant...", @"people":@"Two Million People\nHave Used It", @"added":@(NO)},
|
||||
@{@"title":@"High EQ", @"desc":@"Be Neither Too Close\nNor Too Distant...", @"people":@"Two Million People\nHave Used It", @"added":@(YES)},
|
||||
@{@"title":@"High EQ", @"desc":@"Be Neither Too Close\nNor Too Distant...", @"people":@"Two Million People\nHave Used It", @"added":@(NO)},
|
||||
@{@"title":@"High EQ", @"desc":@"Be Neither Too Close\nNor Too Distant...", @"people":@"Two Million People\nHave Used It", @"added":@(YES)},
|
||||
@{@"title":@"High EQ", @"desc":@"Be Neither Too Close\nNor Too Distant...", @"people":@"Two Million People\nHave Used It", @"added":@(NO)},
|
||||
@{@"title":@"High EQ", @"desc":@"Be Neither Too Close\nNor Too Distant...", @"people":@"Two Million People\nHave Used It", @"added":@(YES)},
|
||||
@{@"title":@"High EQ", @"desc":@"Be Neither Too Close\nNor Too Distant...", @"people":@"Two Million People\nHave Used It", @"added":@(NO)},
|
||||
@{@"title":@"High EQ", @"desc":@"Be Neither Too Close\nNor Too Distant...", @"people":@"Two Million People\nHave Used It", @"added":@(YES)}
|
||||
];
|
||||
|
||||
self.characters = @[];
|
||||
self.homeVM = [KBHomeVM new];
|
||||
|
||||
[self.view addSubview:self.collectionView];
|
||||
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.edges.equalTo(self.view);
|
||||
}];
|
||||
|
||||
// 加载当前 tag 下的角色列表
|
||||
[self loadCharactersForCurrentTag];
|
||||
}
|
||||
|
||||
- (void)loadCharactersForCurrentTag {
|
||||
KBWeakSelf
|
||||
[self.homeVM fetchRankListByTagId:self.tagId
|
||||
needShow:YES
|
||||
completion:^(NSArray<KBCharacter *> * _Nullable list, NSError * _Nullable error) {
|
||||
if (error) {
|
||||
return;
|
||||
}
|
||||
weakSelf.characters = list ?: @[];
|
||||
[weakSelf.collectionView reloadData];
|
||||
}];
|
||||
}
|
||||
|
||||
- (UICollectionView *)collectionView{
|
||||
@@ -66,26 +86,21 @@
|
||||
#pragma mark - UICollectionViewDataSource
|
||||
|
||||
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
|
||||
return self.dataSource.count;
|
||||
return self.characters.count;
|
||||
}
|
||||
|
||||
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
|
||||
HomeRankCardCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeRankCardCell" forIndexPath:indexPath];
|
||||
NSDictionary *d = self.dataSource[indexPath.item];
|
||||
BOOL added = [d[@"added"] boolValue];
|
||||
[cell configureWithTitle:d[@"title"]
|
||||
desc:d[@"desc"]
|
||||
people:d[@"people"]
|
||||
added:added];
|
||||
KBCharacter *c = self.characters[indexPath.item];
|
||||
// 直接把模型交给 cell,由 cell 自己负责展示
|
||||
cell.character = c;
|
||||
KBWeakSelf
|
||||
cell.onTapAction = ^{
|
||||
// 切换添加/已添加状态并刷新该项
|
||||
NSMutableArray *m = [weakSelf.dataSource mutableCopy];
|
||||
NSMutableDictionary *md = [m[indexPath.item] mutableCopy];
|
||||
BOOL cur = [md[@"added"] boolValue];
|
||||
md[@"added"] = @(!cur);
|
||||
m[indexPath.item] = md;
|
||||
weakSelf.dataSource = [m copy];
|
||||
// 切换添加/已添加状态并刷新该项(只是本地 UI 状态)
|
||||
NSMutableArray *m = [weakSelf.characters mutableCopy];
|
||||
KBCharacter *mc = m[indexPath.item];
|
||||
mc.added = !mc.added;
|
||||
weakSelf.characters = [m copy];
|
||||
[weakSelf.collectionView reloadItemsAtIndexPaths:@[indexPath]];
|
||||
};
|
||||
return cell;
|
||||
@@ -105,13 +120,13 @@
|
||||
|
||||
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
|
||||
// 点击卡片 -> 展示弹窗
|
||||
NSDictionary *d = self.dataSource[indexPath.item];
|
||||
KBCharacter *c = self.characters[indexPath.item];
|
||||
|
||||
// 自定义内容视图(尺寸可按需调节)
|
||||
CGFloat width = MIN(KB_SCREEN_WIDTH - 76, 420);
|
||||
HomeRankDetailPopView *content = [[HomeRankDetailPopView alloc] initWithFrame:CGRectMake(0, 0, width, 460)];
|
||||
NSString *title = d[@"title"] ?: @"High EQ";
|
||||
NSString *people = d[@"people"] ?: @"Download: 1 Million";
|
||||
NSString *title = c.characterName ?: @"High EQ";
|
||||
NSString *people = c.download ?: @"Download: 1 Million";
|
||||
NSString *desc = @"Be Neither Too Close\nNor Too Distant"; // 示例文案
|
||||
[content configWithAvatar:nil title:title download:people desc:desc];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user