Files
yuyin_ios/SweetParty/主类/狸猫新增/周星榜/LMWeekListHeaderView.m
2025-08-08 11:05:33 +08:00

87 lines
2.5 KiB
Objective-C

//
// LMWeekListHeaderView.m
// SweetParty
//
// Created by Xmac on 2024/8/7.
//
#import "LMWeekListHeaderView.h"
#import "LMWeekCurrentCollectionViewCell.h"
@interface LMWeekListHeaderView ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic, strong) NSMutableArray *dataArr;
@end
@implementation LMWeekListHeaderView
- (void)awakeFromNib
{
[super awakeFromNib];
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
flowLayout.itemSize = CGSizeMake((APPW-50)/4, 100);
flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
flowLayout.minimumLineSpacing = 0;
self.giftItemView.delegate = self;
self.giftItemView.dataSource = self;
self.giftItemView.collectionViewLayout = flowLayout;
[self.giftItemView registerNib:[UINib nibWithNibName:@"LMWeekCurrentCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:LMWeekCurrentCollectionViewCellID];
[self requestWeekStarGiftList];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return self.dataArr.count;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
LMWeekCurrentCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:LMWeekCurrentCollectionViewCellID forIndexPath:indexPath];
cell.model = self.dataArr[indexPath.row];
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
[self.dataArr enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
LMWeekStarGitfListModel *model = obj;
model.isSelect = NO;
}];
LMWeekStarGitfListModel *model = self.dataArr[indexPath.row];
model.isSelect = YES;
[collectionView reloadData];
if (self.updateListBlock){
self.updateListBlock(model.gid);
}
}
- (void)requestWeekStarGiftList
{
[BJHttpTool BJ_Week_star_gift_listWithParameters:@{} success:^(id response) {
self.dataArr = [LMWeekStarGitfListModel mj_objectArrayWithKeyValuesArray:response[@"data"]];
if (self.dataArr.count > 0){
LMWeekStarGitfListModel *model = self.dataArr[0];
model.isSelect = YES;
if (self.updateListBlock){
self.updateListBlock(model.gid);
}
}
[self.giftItemView reloadData];
} failure:^(NSError *error) {
}];
}
@end