TDGroupLabelVC.m 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // TDGroupLabelVC.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2020/5/8.
  6. // Copyright © 2020 tederen. All rights reserved.
  7. //
  8. #import "TDGroupLabelVC.h"
  9. #import "TDGroupLabelCell.h"
  10. #import "AddGroupLabelVC.h"
  11. @interface TDGroupLabelVC ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
  12. @property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
  13. @property (weak, nonatomic) IBOutlet UIButton *setBtn;
  14. @property (strong, nonatomic) NSArray *dataArray;
  15. @end
  16. @implementation TDGroupLabelVC
  17. +(TDGroupLabelVC *)initTDGroupLabelVC{
  18. TDGroupLabelVC *controller = [StoryboardManager.shared.TDGroup instantiateViewControllerWithIdentifier:@"TDGroupLabelVC"];
  19. return controller;
  20. }
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. self.fd_prefersNavigationBarHidden = YES;
  24. self.collectionView.delegate = self;
  25. self.collectionView.dataSource = self;
  26. [self.collectionView setCollectionViewLayout:[[UICollectionViewFlowLayout alloc] init]];
  27. self.collectionView.showsVerticalScrollIndicator = NO;
  28. self.collectionView.showsHorizontalScrollIndicator = NO;
  29. self.collectionView.contentInset = UIEdgeInsetsMake(2, 30, 0, 24);
  30. [self.collectionView registerNib:[UINib nibWithNibName:@"TDGroupLabelCell" bundle:nil] forCellWithReuseIdentifier:@"TDGroupLabelCell"];
  31. self.collectionView.backgroundColor = [UIColor whiteColor];
  32. self.dataArray = [self.labelName componentsSeparatedByString:@","];
  33. WS(weakSelf);
  34. [self.setBtn setAction:^{
  35. AddGroupLabelVC * vc = [AddGroupLabelVC initAddGroupLabelVC];
  36. vc.array = weakSelf.dataArray;
  37. vc.Id = weakSelf.Id;
  38. vc.refreshDataBlock = ^(NSArray * _Nonnull array) {
  39. weakSelf.dataArray = array;
  40. dispatch_async(dispatch_get_main_queue(), ^{
  41. [weakSelf.collectionView reloadData];
  42. });
  43. if (weakSelf.refreshBlock) {
  44. weakSelf.refreshBlock();
  45. }
  46. };
  47. [weakSelf presentViewController:vc animated:YES completion:^{
  48. }];
  49. }];
  50. }
  51. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  52. return 1;
  53. }
  54. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  55. return self.dataArray.count;
  56. }
  57. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  58. {
  59. return CGSizeMake((SCREEN_WIDTH - 63) * 0.5, 58.f);
  60. }
  61. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
  62. {
  63. return 7.f;
  64. }
  65. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
  66. {
  67. return 9.f;
  68. }
  69. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  70. TDGroupLabelCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TDGroupLabelCell" forIndexPath:indexPath];
  71. cell.titleL.text = self.dataArray[indexPath.item];
  72. cell.deleteBtn.hidden = YES;
  73. return cell;
  74. }
  75. @end