1
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#import "KBTagItemModel.h"
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class KBFunctionTagListView;
|
||||
@@ -19,7 +19,8 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
@property (nonatomic, weak, nullable) id<KBFunctionTagListViewDelegate> delegate;
|
||||
@property (nonatomic, strong, readonly) UICollectionView *collectionView;
|
||||
|
||||
- (void)setItems:(NSArray<NSString *> *)items;
|
||||
//- (void)setItems:(NSArray<NSString *> *)items;
|
||||
- (void)setItems:(NSArray<KBTagItemModel *> *)items;
|
||||
|
||||
/// 在指定 index 上显示/隐藏加载指示(若 cell 不可见,内部会记录状态,待出现时应用)
|
||||
- (void)setLoading:(BOOL)loading atIndex:(NSInteger)index;
|
||||
|
||||
@@ -10,7 +10,7 @@ static CGFloat const kKBItemSpace = 4;
|
||||
|
||||
@interface KBFunctionTagListView () <UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
|
||||
@property (nonatomic, strong) UICollectionView *collectionViewInternal;
|
||||
@property (nonatomic, copy) NSArray<NSString *> *items;
|
||||
@property (nonatomic, copy) NSArray<KBTagItemModel *> *items;
|
||||
@property (nonatomic, strong) NSMutableSet<NSNumber *> *loadingIndexes; // 记录需要展示loading的index
|
||||
@end
|
||||
|
||||
@@ -38,7 +38,8 @@ static CGFloat const kKBItemSpace = 4;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)setItems:(NSArray<NSString *> *)items { _items = [items copy]; [self.collectionViewInternal reloadData]; }
|
||||
//- (void)setItems:(NSArray<NSString *> *)items { _items = [items copy]; [self.collectionViewInternal reloadData]; }
|
||||
- (void)setItems:(NSArray<KBTagItemModel *> *)items{ _items = [items copy]; [self.collectionViewInternal reloadData]; }
|
||||
|
||||
- (UICollectionView *)collectionView { return self.collectionViewInternal; }
|
||||
|
||||
@@ -48,7 +49,8 @@ static CGFloat const kKBItemSpace = 4;
|
||||
|
||||
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
|
||||
KBFunctionTagCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kKBFunctionTagCellId2 forIndexPath:indexPath];
|
||||
cell.titleLabel.text = (indexPath.item < self.items.count) ? self.items[indexPath.item] : @"";
|
||||
KBTagItemModel *itemModel = (indexPath.item < self.items.count) ? self.items[indexPath.item] : [KBTagItemModel new];
|
||||
cell.itemModel = itemModel;
|
||||
BOOL loading = [self.loadingIndexes containsObject:@(indexPath.item)];
|
||||
[cell setLoading:loading];
|
||||
return cell;
|
||||
@@ -65,8 +67,8 @@ static CGFloat const kKBItemSpace = 4;
|
||||
|
||||
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
|
||||
if ([self.delegate respondsToSelector:@selector(tagListView:didSelectIndex:title:)]) {
|
||||
NSString *title = (indexPath.item < self.items.count) ? self.items[indexPath.item] : @"";
|
||||
[self.delegate tagListView:self didSelectIndex:indexPath.item title:title];
|
||||
KBTagItemModel *model = (indexPath.item < self.items.count) ? self.items[indexPath.item] : [KBTagItemModel new];
|
||||
[self.delegate tagListView:self didSelectIndex:indexPath.item title:model.characterName];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user