This commit is contained in:
2025-12-04 19:24:42 +08:00
parent 64887054e0
commit 7a25a6a5fa

View File

@@ -132,13 +132,39 @@
// cell cell
cell.character = c;
KBWeakSelf
__weak typeof(cell) weakCell = cell;
cell.onTapAction = ^{
// / UI
NSMutableArray *m = [weakSelf.characters mutableCopy];
KBCharacter *mc = m[indexPath.item];
mc.added = !mc.added;
weakSelf.characters = [m copy];
[weakSelf.collectionView reloadItemsAtIndexPaths:@[indexPath]];
__strong typeof(weakSelf) self = weakSelf;
HomeRankCardCell *strongCell = weakCell;
if (!self || !strongCell) { return; }
NSIndexPath *currentIndexPath = [collectionView indexPathForCell:strongCell];
if (!currentIndexPath) { return; }
if (currentIndexPath.item >= self.characters.count) { return; }
KBCharacter *mc = self.characters[currentIndexPath.item];
//
if (mc.added) { return; }
NSString *cidStr = mc.ID ?: @"";
if (cidStr.length == 0) { return; }
NSNumber *cid = @([cidStr integerValue]);
[self.homeVM addUserCharacterWithId:cid
completion:^(BOOL success, NSError * _Nullable error) {
if (!success) {
NSString *msg = error.localizedDescription ?: KBLocalized(@"Network error");
[KBHUD showInfo:msg];
return;
}
// item
mc.added = YES;
NSMutableArray *m = [self.characters mutableCopy];
[m replaceObjectAtIndex:currentIndexPath.item withObject:mc];
self.characters = [m copy];
[self.collectionView reloadItemsAtIndexPaths:@[currentIndexPath]];
}];
};
return cell;
}