Files
featherVoice/QXLive/Mine(音域)/View/亲密关系/QXIntimateListCell.m
2025-11-28 22:43:06 +08:00

99 lines
3.8 KiB
Objective-C

//
// QXIntimateListCell.m
// QXLive
//
// Created by 启星 on 2025/11/20.
//
#import "QXIntimateListCell.h"
#import "QXIntimateUserCell.h"
#import "QXUserHomePageViewController.h"
@interface QXIntimateListCell()<UICollectionViewDataSource,UICollectionViewDelegate>
@property (nonatomic,strong)UICollectionView *collectionView;
@end
@implementation QXIntimateListCell
+(instancetype)cellWithTableView:(UITableView *)tableView{
static NSString *cellId = @"QXIntimateListCell";
QXIntimateListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
if (!cell) {
cell = [[QXIntimateListCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:cellId];
cell.backgroundColor = [UIColor clearColor];
}
return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
self.backgroundColor = [UIColor clearColor];
self.contentView.backgroundColor = [UIColor clearColor];
self.selectionStyle = UITableViewCellSelectionStyleNone;
[self initSubviews];
}
return self;
}
-(void)initSubviews{
NSInteger maxCount = 3;
NSInteger margin = 14;
CGFloat btnWith = (int)(SCREEN_WIDTH-48-14*2-1)/maxCount;
CGFloat btnHeight = ScaleWidth(125);
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.itemSize = CGSizeMake(btnWith, btnHeight);
layout.minimumLineSpacing = 0;
layout.minimumInteritemSpacing = 14;
layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
layout.scrollDirection = UICollectionViewScrollDirectionVertical;
self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
[self.collectionView registerNib:[UINib nibWithNibName:@"QXIntimateUserCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"QXIntimateUserCell"];
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
self.collectionView.showsHorizontalScrollIndicator = NO;
self.collectionView.bounces = NO;
self.collectionView.backgroundColor = UIColor.clearColor;
[self.contentView addSubview:self.collectionView];
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.bottom.equalTo(self.contentView);
make.left.mas_equalTo(24);
make.right.mas_equalTo(-24);
}];
}
-(void)setModel:(QXRoomBestFriendListModel *)model{
_model = model;
[self.collectionView reloadData];
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return self.model.relation_list.count;
}
-(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
QXIntimateUserCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXIntimateUserCell" forIndexPath:indexPath];
cell.userId = self.userId;
cell.model = self.model.relation_list[indexPath.row];
return cell;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
QXRelationshipListModel *md = self.model.relation_list[indexPath.row];
NSString *userId = @"";
if ([md.user_id1 isEqualToString:self.userId]) {
userId = md.user_id2;
}else{
userId = md.user_id1;
}
QXUserHomePageViewController *vc = [[QXUserHomePageViewController alloc] init];
vc.user_id = userId;
[self.viewController.navigationController pushViewController:vc animated:YES];
}
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end