11
This commit is contained in:
@@ -72,14 +72,34 @@ static NSString * const kKBMyKeyboardCellId = @"kKBMyKeyboardCellId";
|
||||
make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom).offset(-12);
|
||||
make.height.mas_equalTo(50);
|
||||
}];
|
||||
|
||||
// 初始数据
|
||||
// [self buildDefaultData];
|
||||
|
||||
// 使用后端真实数据初始化列表
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[self.viewModel fetchCharacterListByUserWithCompletion:^(NSArray<KBCharacter *> * _Nonnull characterArray, NSError * _Nullable error) {
|
||||
if (characterArray.count > 0) {
|
||||
|
||||
// 请求失败或无数据时,不再使用本地测试数据,直接清空展示
|
||||
if (error || characterArray.count == 0) {
|
||||
weakSelf.dataSourceArray = [NSMutableArray array];
|
||||
[weakSelf.collectionView reloadData];
|
||||
return;
|
||||
}
|
||||
|
||||
// 将 KBCharacter 模型转换为当前列表使用的 {emoji, title} 结构
|
||||
NSMutableArray<NSDictionary *> *section = [NSMutableArray arrayWithCapacity:characterArray.count];
|
||||
for (KBCharacter *c in characterArray) {
|
||||
NSString *emoji = c.emoji ?: @"";
|
||||
NSString *title = c.characterName ?: @"";
|
||||
// 如果某条数据既没有 emoji 也没有标题,则忽略
|
||||
if (emoji.length == 0 && title.length == 0) {
|
||||
continue;
|
||||
}
|
||||
[section addObject:@{@"emoji": emoji, @"title": title}];
|
||||
}
|
||||
|
||||
weakSelf.dataSourceArray = [NSMutableArray array];
|
||||
if (section.count > 0) {
|
||||
[weakSelf.dataSourceArray addObject:section];
|
||||
}
|
||||
[weakSelf.collectionView reloadData];
|
||||
}];
|
||||
}
|
||||
|
||||
@@ -100,59 +120,6 @@ static NSString * const kKBMyKeyboardCellId = @"kKBMyKeyboardCellId";
|
||||
|
||||
#pragma mark - Data
|
||||
|
||||
/// 构造示例数据(二维数组,仅 1 个 section)
|
||||
- (void)buildDefaultData {
|
||||
NSArray *arr = @[
|
||||
@{@"emoji":@"😊", @"title":@"Humor"},
|
||||
@{@"emoji":@"😄", @"title":@"Jokes"},
|
||||
@{@"emoji":@"🥰", @"title":@"Love"},
|
||||
@{@"emoji":@"🤔", @"title":@"Thinking"},
|
||||
@{@"emoji":@"🔥", @"title":@"Hot"},
|
||||
@{@"emoji":@"🎉", @"title":@"Celebrate"},
|
||||
@{@"emoji":@"🧠", @"title":@"Brainstorm"},
|
||||
@{@"emoji":@"🐱", @"title":@"Cats"},
|
||||
@{@"emoji":@"😂", @"title":@"LOL"},
|
||||
@{@"emoji":@"📸", @"title":@"Photography"},
|
||||
@{@"emoji":@"🌟", @"title":@"Star"},
|
||||
@{@"emoji":@"🍀", @"title":@"Lucky"},
|
||||
@{@"emoji":@"📚", @"title":@"Knowledge"},
|
||||
@{@"emoji":@"🎵", @"title":@"Music"},
|
||||
@{@"emoji":@"🚀", @"title":@"Launch"},
|
||||
@{@"emoji":@"😊", @"title":@"Humor"},
|
||||
@{@"emoji":@"😄", @"title":@"Jokes"},
|
||||
@{@"emoji":@"🥰", @"title":@"Love"},
|
||||
@{@"emoji":@"🤔", @"title":@"Thinking"},
|
||||
@{@"emoji":@"🔥", @"title":@"Hot"},
|
||||
@{@"emoji":@"🎉", @"title":@"Celebrate"},
|
||||
@{@"emoji":@"🧠", @"title":@"Brainstorm"},
|
||||
@{@"emoji":@"🐱", @"title":@"Cats"},
|
||||
@{@"emoji":@"😂", @"title":@"LOL"},
|
||||
@{@"emoji":@"📸", @"title":@"Photography"},
|
||||
@{@"emoji":@"🌟", @"title":@"Star"},
|
||||
@{@"emoji":@"🍀", @"title":@"Lucky"},
|
||||
@{@"emoji":@"📚", @"title":@"Knowledge"},
|
||||
@{@"emoji":@"🎵", @"title":@"Music"},
|
||||
@{@"emoji":@"🚀", @"title":@"Launch"},
|
||||
@{@"emoji":@"😊", @"title":@"Humor"},
|
||||
@{@"emoji":@"😄", @"title":@"Jokes"},
|
||||
@{@"emoji":@"🥰", @"title":@"Love"},
|
||||
@{@"emoji":@"🤔", @"title":@"Thinking"},
|
||||
@{@"emoji":@"🔥", @"title":@"Hot"},
|
||||
@{@"emoji":@"🎉", @"title":@"Celebrate"},
|
||||
@{@"emoji":@"🧠", @"title":@"Brainstorm"},
|
||||
@{@"emoji":@"🐱", @"title":@"Cats"},
|
||||
@{@"emoji":@"😂", @"title":@"LOL"},
|
||||
@{@"emoji":@"📸", @"title":@"Photography"},
|
||||
@{@"emoji":@"🌟", @"title":@"Star"},
|
||||
@{@"emoji":@"🍀", @"title":@"Lucky"},
|
||||
@{@"emoji":@"📚", @"title":@"Knowledge"},
|
||||
@{@"emoji":@"🎵", @"title":@"Music"},
|
||||
@{@"emoji":@"🚀", @"title":@"Launch"},
|
||||
];
|
||||
self.dataSourceArray = [@[[arr mutableCopy]] mutableCopy];
|
||||
[self.collectionView reloadData];
|
||||
}
|
||||
|
||||
#pragma mark - BMLongPressDragCellCollectionViewDataSource
|
||||
|
||||
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return self.dataSourceArray.count; }
|
||||
|
||||
Reference in New Issue
Block a user