1
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
#import "HomeRankCardCell.h"
|
||||
#import "KBHomeVM.h"
|
||||
#import "KBCharacter.h"
|
||||
#import "KBMyVM.h" // 引入用户人设变更通知
|
||||
|
||||
@interface HomeRankContentVC ()
|
||||
@property (nonatomic, copy, nullable) NSString *tagId; // 当前标签 id
|
||||
@@ -46,14 +47,29 @@
|
||||
make.edges.equalTo(self.view);
|
||||
}];
|
||||
|
||||
// 监听“用户人设删除”通知,用于同步更新加号按钮状态
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(kb_onUserCharacterDeleted:)
|
||||
name:KBUserCharacterDeletedNotification
|
||||
object:nil];
|
||||
|
||||
// 加载当前 tag 下的角色列表
|
||||
[self loadCharactersForCurrentTag];
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
}
|
||||
|
||||
- (void)loadCharactersForCurrentTag {
|
||||
[self kb_requestCharactersWithShowHUD:YES];
|
||||
}
|
||||
|
||||
// 内部通用方法:根据 tag 请求角色列表
|
||||
- (void)kb_requestCharactersWithShowHUD:(BOOL)needShow {
|
||||
KBWeakSelf
|
||||
[self.homeVM fetchRankListByTagId:self.tagId
|
||||
needShow:YES
|
||||
needShow:needShow
|
||||
completion:^(NSArray<KBCharacter *> * _Nullable list, NSError * _Nullable error) {
|
||||
if (error) {
|
||||
return;
|
||||
@@ -63,6 +79,26 @@
|
||||
}];
|
||||
}
|
||||
|
||||
/// 收到“用户人设删除”通知:如果当前列表包含该 id,则刷新接口数据
|
||||
- (void)kb_onUserCharacterDeleted:(NSNotification *)note {
|
||||
NSNumber *cid = note.userInfo[@"characterId"];
|
||||
if (!cid) { return; }
|
||||
NSInteger targetId = cid.integerValue;
|
||||
if (targetId <= 0) { return; }
|
||||
|
||||
BOOL contains = NO;
|
||||
for (KBCharacter *c in self.characters) {
|
||||
if (c.characterId.integerValue == targetId) {
|
||||
contains = YES;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!contains) { return; }
|
||||
|
||||
// 后端会根据最新的人设状态返回 added 字段,刷新本页 UI
|
||||
[self kb_requestCharactersWithShowHUD:NO];
|
||||
}
|
||||
|
||||
- (UICollectionView *)collectionView{
|
||||
if (!_collectionView) {
|
||||
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
||||
|
||||
Reference in New Issue
Block a user