You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
107 lines
3.7 KiB
107 lines
3.7 KiB
![]()
2 years ago
|
//
|
||
|
// NewCollectionTableViewCell.m
|
||
|
// tongxin
|
||
|
//
|
||
|
// Created by WeiChaoZheng on 2018/6/27.
|
||
|
// Copyright © 2018年 xTT. All rights reserved.
|
||
|
//
|
||
|
|
||
|
#import "NewCollectionTableViewCell.h"
|
||
|
#import "NewCollectionViewCell.h"
|
||
|
#import "User.h"
|
||
|
#import "Device.h"
|
||
|
|
||
|
@interface NewCollectionTableViewCell()
|
||
|
|
||
|
|
||
|
@end
|
||
|
@implementation NewCollectionTableViewCell
|
||
|
|
||
|
-(NSArray *)collectionDataSource{
|
||
|
if (!_collectionDataSource) {
|
||
|
_collectionDataSource = [myHelper getRelationshipNameArr:self.deviceType.integerValue];
|
||
|
}
|
||
|
return _collectionDataSource;
|
||
|
}
|
||
|
|
||
|
|
||
|
- (void)awakeFromNib {
|
||
|
[super awakeFromNib];
|
||
|
// self.backView.layer.cornerRadius = 3;
|
||
|
// self.backView.layer.masksToBounds = YES;
|
||
|
self.selectionStyle = UITableViewCellSelectionStyleNone;
|
||
|
[self initCollectionView];
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
-(void)initCollectionView{
|
||
|
//注册 cell
|
||
|
[self.collectionView registerNib:[UINib nibWithNibName:@"NewCollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"NewCollectionViewCellID"];
|
||
|
self.collectionView.delegate = self;
|
||
|
self.collectionView.dataSource = self;
|
||
|
}
|
||
|
|
||
|
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
|
||
|
return self.collectionDataSource.count;
|
||
|
}
|
||
|
|
||
|
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
|
||
|
{
|
||
|
return CGSizeMake(75, 100);
|
||
|
}
|
||
|
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
|
||
|
return UIEdgeInsetsMake(0, 29, 0, 29);
|
||
|
}
|
||
|
//设置水平间距 (同一行的cell的左右间距)
|
||
|
|
||
|
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
|
||
|
|
||
|
return 17;
|
||
|
|
||
|
}
|
||
|
//垂直间距 (同一列cell上下间距)
|
||
|
|
||
|
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
|
||
|
|
||
|
return 5;
|
||
|
|
||
|
}
|
||
|
|
||
|
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
|
||
|
NewCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"NewCollectionViewCellID" forIndexPath:indexPath];
|
||
|
|
||
|
cell.nameLabel.text = self.collectionDataSource[indexPath.item];
|
||
|
if (self.contactcode == indexPath.row+1){
|
||
|
[cell setSelectWithThisItem:YES];
|
||
|
// cell.imageVIew.image = [UIImage imageNamed:self.imageNameArr[indexPath.item]];
|
||
|
cell.imageVIew.image = [myHelper getClickRelationshipImageWithCodeID:indexPath.row+1 deviceType:self.deviceType.integerValue];
|
||
|
}else{
|
||
|
// cell.imageVIew.image = [UIImage imageNamed:self.unclickImageNameArr[indexPath.item]];
|
||
|
cell.imageVIew.image = [myHelper getUnclickRelationshipImageWithCodeID:indexPath.item+1 deviceType:self.deviceType.integerValue];
|
||
|
[cell setSelectWithThisItem:NO];
|
||
|
}
|
||
|
return cell;
|
||
|
}
|
||
|
|
||
|
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
|
||
|
// NewCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"NewCollectionViewCellID" forIndexPath:indexPath];
|
||
|
// [cell setSelectWithThisItem:YES];
|
||
|
NSString *contect = self.collectionDataSource[indexPath.item];
|
||
|
self.contactcode = indexPath.item+1;
|
||
|
if(self.selectContactBlock){
|
||
|
self.selectContactBlock(contect, self.contactcode);
|
||
|
}
|
||
|
[collectionView reloadData];
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
|
||
|
[super setSelected:selected animated:animated];
|
||
|
|
||
|
// Configure the view for the selected state
|
||
|
}
|
||
|
|
||
|
@end
|