1
This commit is contained in:
@@ -109,7 +109,9 @@ static NSString * const kKBMyKeyboardCellId = @"kKBMyKeyboardCellId";
|
||||
for (KBCharacter *c in characterArray) {
|
||||
NSString *emoji = c.emoji ?: @"";
|
||||
NSString *title = c.characterName ?: @"";
|
||||
NSString *identifier = c.characterId ?: @"";
|
||||
NSString *identifier = c.ID ?: @"";
|
||||
NSString *characterId = c.characterId ?: @"";
|
||||
|
||||
// 如果某条数据既没有 emoji 也没有标题,则忽略
|
||||
if (emoji.length == 0 && title.length == 0) {
|
||||
continue;
|
||||
@@ -117,6 +119,8 @@ static NSString * const kKBMyKeyboardCellId = @"kKBMyKeyboardCellId";
|
||||
NSMutableDictionary *item = [NSMutableDictionary dictionary];
|
||||
item[@"emoji"] = emoji;
|
||||
item[@"title"] = title;
|
||||
item[@"characterId"] = characterId;
|
||||
|
||||
if (identifier.length > 0) {
|
||||
// 用数字类型存储,便于直接作为 sort 数组上送
|
||||
NSInteger cid = identifier.integerValue;
|
||||
@@ -154,18 +158,21 @@ static NSString * const kKBMyKeyboardCellId = @"kKBMyKeyboardCellId";
|
||||
if (!tapIndexPath) { return; }
|
||||
|
||||
// 取出将要删除的人设 id
|
||||
NSNumber *characterId = nil;
|
||||
NSNumber *delId = nil; // 要删除的ID
|
||||
NSString *characterId = @""; // 通知其他页面要刷新的关联ID
|
||||
|
||||
if (tapIndexPath.section < self.dataSourceArray.count) {
|
||||
NSArray *section = self.dataSourceArray[tapIndexPath.section];
|
||||
if (tapIndexPath.item < section.count) {
|
||||
NSDictionary *item = section[tapIndexPath.item];
|
||||
id cid = item[@"id"];
|
||||
characterId = item[@"characterId"];
|
||||
if ([cid isKindOfClass:[NSNumber class]]) {
|
||||
characterId = (NSNumber *)cid;
|
||||
delId = (NSNumber *)cid;
|
||||
} else if ([cid isKindOfClass:[NSString class]]) {
|
||||
NSString *cidStr = (NSString *)cid;
|
||||
if (cidStr.length > 0) {
|
||||
characterId = @([cidStr integerValue]);
|
||||
delId = @([cidStr integerValue]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -181,7 +188,7 @@ static NSString * const kKBMyKeyboardCellId = @"kKBMyKeyboardCellId";
|
||||
if (!ok) { return; }
|
||||
|
||||
// 若无法获取 id,仅做本地删除以保持 UI 一致
|
||||
if (!characterId) {
|
||||
if (!delId) {
|
||||
if (tapIndexPath.section < self.dataSourceArray.count) {
|
||||
NSMutableArray *section = self.dataSourceArray[tapIndexPath.section];
|
||||
if (tapIndexPath.item < section.count) {
|
||||
@@ -196,7 +203,7 @@ static NSString * const kKBMyKeyboardCellId = @"kKBMyKeyboardCellId";
|
||||
|
||||
// 调用删除接口,成功后刷新界面
|
||||
__weak typeof(self) weakSelf2 = self;
|
||||
[self.viewModel deleteUserCharacterWithId:characterId
|
||||
[self.viewModel deleteUserCharacterWithId:delId
|
||||
completion:^(BOOL success, NSError * _Nullable error) {
|
||||
__strong typeof(weakSelf2) strongSelf = weakSelf2;
|
||||
if (!strongSelf) { return; }
|
||||
@@ -206,7 +213,13 @@ static NSString * const kKBMyKeyboardCellId = @"kKBMyKeyboardCellId";
|
||||
[KBHUD showInfo:msg];
|
||||
return;
|
||||
}
|
||||
|
||||
// 通知 App 内其他页面(如 HomeRankContentVC / HomeHotVC)该人设已被删除
|
||||
NSDictionary *info = @{@"characterId": characterId ?: @0};
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:KBUserCharacterDeletedNotification
|
||||
object:nil
|
||||
userInfo:info];
|
||||
});
|
||||
// 重新拉取用户人设列表,刷新 UI
|
||||
[strongSelf kb_reloadUserCharacters];
|
||||
}];
|
||||
|
||||
Reference in New Issue
Block a user