AddDevece_VC.m 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //
  2. // AddDevece_VC.m
  3. // Haishenghai-master
  4. //
  5. // Created by GG on 2019/1/3.
  6. // Copyright © 2019年 Haishenghai intelligence network technology. All rights reserved.
  7. //
  8. #import "AddDevece_VC.h"
  9. #import "deveceModel.h"
  10. @interface AddDevece_VC ()<UICollectionViewDataSource,UICollectionViewDelegate>
  11. @end
  12. @implementation AddDevece_VC
  13. -(void)viewWillAppear:(BOOL)animated{
  14. [super viewWillAppear:animated];
  15. }
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. [self setupUI];
  19. self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:60/255.0 green:114/255.0 blue:255/255.0 alpha:1];
  20. [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:18],NSForegroundColorAttributeName:[UIColor whiteColor]}];
  21. //设置导航栏左侧按钮
  22. UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  23. [backBtn setImage:[UIImage imageNamed:@"hsh_return"] forState:UIControlStateNormal];
  24. backBtn.frame = CGRectMake(0, 0, 44, 44);
  25. [backBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
  26. backBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  27. self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backBtn];
  28. self.dataArray = [[NSMutableArray alloc]initWithCapacity:0];
  29. [DataSourceManager queryDevecetypeWithcompletionBlock:^(NSMutableArray *array) {
  30. self.dataArray = array;
  31. [_collectionView reloadData];
  32. NSLog(@"%@",self.dataArray);
  33. }];
  34. }
  35. -(void)backClick{
  36. [self.navigationController popViewControllerAnimated:YES];
  37. }
  38. -(void)setupUI{
  39. self.view.backgroundColor = [UIColor whiteColor];
  40. self.navigationItem.title =@"设备列表";
  41. [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:20],NSForegroundColorAttributeName:[UIColor whiteColor]}];
  42. self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:60/255.0 green:114/255.0 blue:255/255.0 alpha:1];
  43. UIBarButtonItem *backIetm = [[UIBarButtonItem alloc] init];
  44. backIetm.title = @"返回";
  45. self.navigationItem.backBarButtonItem = backIetm;
  46. self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"" style:UIBarButtonItemStylePlain target:self action:nil];
  47. //
  48. UICollectionViewFlowLayout *layout =[[UICollectionViewFlowLayout alloc]init];
  49. layout.sectionInset =UIEdgeInsetsMake(5, 5, 5, 5);
  50. layout.itemSize =CGSizeMake(80, 120);
  51. layout.minimumInteritemSpacing =5;
  52. _collectionView =[[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) collectionViewLayout:layout];
  53. _collectionView.delegate =self;
  54. _collectionView.dataSource =self;
  55. _collectionView.backgroundColor =[UIColor whiteColor];
  56. _collectionView.showsHorizontalScrollIndicator = NO;
  57. [self.view addSubview:_collectionView];
  58. // 注册cell、sectionHeader、sectionFooter
  59. [_collectionView registerClass:[CollectionViewCell class] forCellWithReuseIdentifier:@"cellId"];
  60. }
  61. #pragma UIcollectionViewDataSourse
  62. //设置item
  63. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  64. {
  65. return self.dataArray.count;
  66. }
  67. //设置区
  68. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
  69. {
  70. return 1;
  71. }
  72. //设置Item详细信息
  73. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  74. {
  75. CollectionViewCell *cell = [_collectionView dequeueReusableCellWithReuseIdentifier:@"cellId" forIndexPath:indexPath];
  76. // cell.backgroundColor = [UIColor redColor];
  77. // 显示数据
  78. deveceModel *model = [_dataArray objectAtIndex:indexPath.row];
  79. NSArray *imgArr = @[@"hsh_home_equipment_smoke"];
  80. // NSArray *titleArr = @[@"烟感探测器",@"其他"];
  81. // NSString *str = [NSString stringWithFormat:@"https://www.hsh-iot.cn/%@",model.typePic];
  82. // NSURL *imageURL = [NSURL URLWithString:str];
  83. // NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
  84. //
  85. // cell.topImage.image =[UIImage imageWithData:imageData];
  86. cell.topImage.image =[UIImage imageNamed:[NSString stringWithFormat:@"%@",[imgArr objectAtIndex:indexPath.row]]];
  87. cell.botlabel.text =model.groupName;
  88. self.titleName = model.groupName;
  89. _deveceTypeID = [model.ID intValue];
  90. return cell;
  91. }
  92. // 选中某item
  93. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  94. {
  95. // 设置默认选中第一个cell
  96. NSLog(@"%ld",(long)indexPath.row);
  97. ScanViewController *scanVC = [[ScanViewController alloc]init];
  98. scanVC.deveceName = self.titleName;
  99. NSLog(@"%d",_deveceTypeID);
  100. scanVC.typeId = _deveceTypeID;
  101. [self.navigationController pushViewController:scanVC animated:YES];
  102. //扫一扫
  103. }
  104. - (void)didReceiveMemoryWarning {
  105. [super didReceiveMemoryWarning];
  106. // Dispose of any resources that can be recreated.
  107. }
  108. /*
  109. #pragma mark - Navigation
  110. // In a storyboard-based application, you will often want to do a little preparation before navigation
  111. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  112. // Get the new view controller using [segue destinationViewController].
  113. // Pass the selected object to the new view controller.
  114. }
  115. */
  116. @end