| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- //
- // AddDevece_VC.m
- // Haishenghai-master
- //
- // Created by GG on 2019/1/3.
- // Copyright © 2019年 Haishenghai intelligence network technology. All rights reserved.
- //
- #import "AddDevece_VC.h"
- #import "deveceModel.h"
- @interface AddDevece_VC ()<UICollectionViewDataSource,UICollectionViewDelegate>
- @end
- @implementation AddDevece_VC
- -(void)viewWillAppear:(BOOL)animated{
- [super viewWillAppear:animated];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self setupUI];
- self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:60/255.0 green:114/255.0 blue:255/255.0 alpha:1];
- [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:18],NSForegroundColorAttributeName:[UIColor whiteColor]}];
- //设置导航栏左侧按钮
- UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [backBtn setImage:[UIImage imageNamed:@"hsh_return"] forState:UIControlStateNormal];
- backBtn.frame = CGRectMake(0, 0, 44, 44);
- [backBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
- backBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
- self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backBtn];
-
- self.dataArray = [[NSMutableArray alloc]initWithCapacity:0];
- [DataSourceManager queryDevecetypeWithcompletionBlock:^(NSMutableArray *array) {
- self.dataArray = array;
- [_collectionView reloadData];
- NSLog(@"%@",self.dataArray);
- }];
- }
- -(void)backClick{
- [self.navigationController popViewControllerAnimated:YES];
- }
- -(void)setupUI{
- self.view.backgroundColor = [UIColor whiteColor];
- self.navigationItem.title =@"设备列表";
- [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:20],NSForegroundColorAttributeName:[UIColor whiteColor]}];
- self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:60/255.0 green:114/255.0 blue:255/255.0 alpha:1];
- UIBarButtonItem *backIetm = [[UIBarButtonItem alloc] init];
- backIetm.title = @"返回";
- self.navigationItem.backBarButtonItem = backIetm;
- self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"" style:UIBarButtonItemStylePlain target:self action:nil];
- //
- UICollectionViewFlowLayout *layout =[[UICollectionViewFlowLayout alloc]init];
- layout.sectionInset =UIEdgeInsetsMake(5, 5, 5, 5);
- layout.itemSize =CGSizeMake(80, 120);
- layout.minimumInteritemSpacing =5;
- _collectionView =[[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) collectionViewLayout:layout];
- _collectionView.delegate =self;
- _collectionView.dataSource =self;
- _collectionView.backgroundColor =[UIColor whiteColor];
- _collectionView.showsHorizontalScrollIndicator = NO;
- [self.view addSubview:_collectionView];
- // 注册cell、sectionHeader、sectionFooter
- [_collectionView registerClass:[CollectionViewCell class] forCellWithReuseIdentifier:@"cellId"];
- }
- #pragma UIcollectionViewDataSourse
- //设置item
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
- {
-
- return self.dataArray.count;
- }
- //设置区
- - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
- {
- return 1;
- }
- //设置Item详细信息
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
- {
- CollectionViewCell *cell = [_collectionView dequeueReusableCellWithReuseIdentifier:@"cellId" forIndexPath:indexPath];
- // cell.backgroundColor = [UIColor redColor];
- // 显示数据
- deveceModel *model = [_dataArray objectAtIndex:indexPath.row];
- NSArray *imgArr = @[@"hsh_home_equipment_smoke"];
- // NSArray *titleArr = @[@"烟感探测器",@"其他"];
- // NSString *str = [NSString stringWithFormat:@"https://www.hsh-iot.cn/%@",model.typePic];
- // NSURL *imageURL = [NSURL URLWithString:str];
- // NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
- //
- // cell.topImage.image =[UIImage imageWithData:imageData];
- cell.topImage.image =[UIImage imageNamed:[NSString stringWithFormat:@"%@",[imgArr objectAtIndex:indexPath.row]]];
- cell.botlabel.text =model.groupName;
- self.titleName = model.groupName;
- _deveceTypeID = [model.ID intValue];
- return cell;
- }
- // 选中某item
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
- {
-
- // 设置默认选中第一个cell
- NSLog(@"%ld",(long)indexPath.row);
- ScanViewController *scanVC = [[ScanViewController alloc]init];
- scanVC.deveceName = self.titleName;
- NSLog(@"%d",_deveceTypeID);
- scanVC.typeId = _deveceTypeID;
- [self.navigationController pushViewController:scanVC animated:YES];
- //扫一扫
-
-
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|