CGPTCell.m 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //
  2. // CGPTCell.m
  3. // jitao
  4. //
  5. // Created by 罗云飞 on 2018/1/20.
  6. // Copyright © 2018年 罗云飞. All rights reserved.
  7. //
  8. #import "CGPTCell.h"
  9. #import "CGPTCollectionViewCell.h"
  10. @implementation CGPTCell{
  11. UICollectionViewFlowLayout *flowLayout;
  12. NSMutableArray *dataArray;
  13. }
  14. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
  15. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  16. if (self) {
  17. dataArray = NewMutableArrayInit;
  18. [self.contentView addSubview:_CollView = [NewControlPackage collectionViewInitWithFrame:CGRectMake(0.0, 0.6, SCREEN_WIDTH, 240) delegate:self dataSource:self backgroundColor:NewWhiteColor scrollEnabled:YES alwaysBounceVertical:YES alwaysBounceHorizontal:NO showsHorizontalScrollIndicator:NO showsVerticalScrollIndicator:NO collectionViewFlowLayout:flowLayout sectionInset:UIEdgeInsetsMake(0, 0, 0, 0) headerReference:CGSizeMake(0, 0) footerReference:CGSizeMake(0, 0) minimumInteritemSpacing:0 minimumLineSpacing:0 scrollDirection:0 hidden:NO tag:105 userInteractionEnabled:YES]];
  19. [_CollView registerClass:[CGPTCollectionViewCell class] forCellWithReuseIdentifier:@"CGPTCollViewCell"];
  20. }
  21. return self;
  22. }
  23. //定义展示的UICollectionViewCell的个数
  24. -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  25. {
  26. if (dataArray.count == 3) {
  27. return dataArray.count;
  28. }else{
  29. return dataArray.count+1;
  30. }
  31. }
  32. //定义展示的Section的个数
  33. -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
  34. {
  35. return 1;
  36. }
  37. //每个UICollectionView展示的内容
  38. -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  39. {
  40. // HomeModel *HModel = [self.HomeArray objectAtIndex:indexPath.row];
  41. CGPTCollectionViewCell *collcell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CGPTCollViewCell" forIndexPath:indexPath];
  42. collcell.backgroundColor = NewWhiteColor;
  43. if (indexPath.row == dataArray.count) {
  44. [collcell.incoImage setImage:NewImageNamed(@"AddMedia")];
  45. collcell.deleteButton.hidden = YES;
  46. }else{
  47. [collcell.incoImage setImage:NewImageNamed(@"")];
  48. collcell.deleteButton.hidden = NO;
  49. if (dataArray.count>0) {
  50. [collcell SetCollCellData:dataArray[indexPath.row]];
  51. }
  52. }
  53. collcell.deleteButton.tag = indexPath.row;
  54. NewTouchUpInside(collcell.deleteButton, deleteButtonclick:);
  55. return collcell;
  56. }
  57. #pragma mark --UICollectionViewDelegateFlowLayout
  58. //定义每个UICollectionView 的大小
  59. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  60. {
  61. return CGSizeMake(SCREEN_WIDTH/2-20, 100);
  62. }
  63. //定义每个UICollectionView 的 margin 边距 上左下右
  64. -(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
  65. {
  66. return UIEdgeInsetsMake(0, 15, 0, 15);
  67. }
  68. #pragma mark --UICollectionViewDelegate
  69. //UICollectionView被选中时调用的方法
  70. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  71. {
  72. if (indexPath.row == dataArray.count) {
  73. if([self.delegateColl respondsToSelector:@selector(CGPTColldelegateClickCooRow:)])
  74. {
  75. [self.delegateColl CGPTColldelegateClickCooRow:indexPath.row];
  76. }
  77. }else{
  78. NSLog(@"1");
  79. }
  80. // UICollectionViewCell * cell = (UICollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
  81. // cell.backgroundColor = [UIColor whiteColor];
  82. // //代理传值
  83. // CollCell *cell = (CollCell *)[collectionView cellForItemAtIndexPath:indexPath];
  84. // luoluo = indexPath.row;
  85. // [_CollView reloadData];
  86. }
  87. - (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath{
  88. // CollCell *cell = (CollCell *)[collectionView cellForItemAtIndexPath:indexPath];
  89. // cell.type.textColor = NewButtonColor;
  90. // cell.type.backgroundColor = NewWhiteColor;
  91. // [_CollView reloadData];
  92. }
  93. - (void)reloadDatas:(NSMutableArray *)arr {
  94. [dataArray removeAllObjects];
  95. [dataArray addObjectsFromArray:arr];
  96. [_CollView reloadData];
  97. }
  98. - (void)deleteButtonclick:(UIButton *)sender {
  99. NSLog(@"111");
  100. if([self.delegateColl respondsToSelector:@selector(hahahaha:)])
  101. {
  102. [self.delegateColl hahahaha:sender.tag];
  103. }
  104. [dataArray removeObjectAtIndex:sender.tag];
  105. [_CollView reloadData];
  106. }
  107. - (void)awakeFromNib {
  108. [super awakeFromNib];
  109. // Initialization code
  110. }
  111. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  112. [super setSelected:selected animated:animated];
  113. // Configure the view for the selected state
  114. }
  115. @end