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 cell
cell.character = c; cell.character = c;
KBWeakSelf KBWeakSelf
__weak typeof(cell) weakCell = cell;
cell.onTapAction = ^{ cell.onTapAction = ^{
// / UI __strong typeof(weakSelf) self = weakSelf;
NSMutableArray *m = [weakSelf.characters mutableCopy]; HomeRankCardCell *strongCell = weakCell;
KBCharacter *mc = m[indexPath.item]; if (!self || !strongCell) { return; }
mc.added = !mc.added;
weakSelf.characters = [m copy]; NSIndexPath *currentIndexPath = [collectionView indexPathForCell:strongCell];
[weakSelf.collectionView reloadItemsAtIndexPaths:@[indexPath]]; 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; return cell;
} }