DeveceDetail_VC.m 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. //
  2. // DeveceDetail_VC.m
  3. // Haishenghai-master
  4. //
  5. // Created by GG on 2019/1/4.
  6. // Copyright © 2019年 Haishenghai intelligence network technology. All rights reserved.
  7. //
  8. #import "DeveceDetail_VC.h"
  9. #import "TableheaderView.h"
  10. @interface DeveceDetail_VC ()<UITableViewDelegate,UITableViewDataSource>
  11. @property (nonatomic,copy)NSString *state;
  12. @property (nonatomic,strong)UITableView *myTable;
  13. @property (nonatomic,strong)UIView *headerView;
  14. @property (nonatomic,strong)NSMutableArray *dataArray;
  15. @end
  16. /**自定义时间轴单元格 */
  17. @implementation DeveceDetail_VC
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. self.view.backgroundColor = [UIColor whiteColor];
  21. self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:60/255.0 green:114/255.0 blue:255/255.0 alpha:1];
  22. [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:18],NSForegroundColorAttributeName:[UIColor whiteColor]}];
  23. UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  24. [backBtn setImage:[UIImage imageNamed:@"hsh_return"] forState:UIControlStateNormal];
  25. backBtn.frame = CGRectMake(0, 0, 44, 44);
  26. [backBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
  27. backBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  28. self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backBtn];
  29. self.navigationItem.title =@"设备详情";
  30. // if (@available (iOS 11.0,*)) {
  31. // self.myTable.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  32. // }else{
  33. // self.automaticallyAdjustsScrollViewInsets = NO;
  34. // }
  35. [self setupUI];
  36. [DataSourceManager getDeveceDataChangedWithUrluploadDeveceID:_deveceID Page:1 Pagesize:100 completionBlock:^(NSMutableArray *array) {
  37. _dataArray =array;
  38. [_myTable reloadData];
  39. }];
  40. }
  41. -(void)backClick{
  42. [self.navigationController popViewControllerAnimated:YES];
  43. }
  44. -(void)setupUI{
  45. [self.view addSubview:_myTable];
  46. //设置表头 //需要自定义headerView+model数据型的
  47. TableheaderView *view = [[TableheaderView alloc]init];
  48. view.frame = CGRectMake(0, 0, WIDTH, 110);
  49. self.myTable.tableHeaderView = view;
  50. self.myTable.showsVerticalScrollIndicator = NO;
  51. // view.backgroundColor = [UIColor grayColor];
  52. // [_headerView addSubview:view];
  53. view.nameLabel.text = _deviceName;
  54. if ([_state isEqualToString:@"1"]) {
  55. view.stateLabel.text = @"火警";
  56. view.stateLabel.textColor = [UIColor redColor];
  57. }
  58. view.detailLabel.text = @"电信运营商";
  59. view.numberLabel.text = _deveceID;
  60. view.locationLabel.text = _location;
  61. view.d_locationLabel.text = _d_location;
  62. }
  63. #pragma mark--lazy--------
  64. -(UITableView *)myTable{
  65. if (!_myTable) {
  66. UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT) style:UITableViewStylePlain];
  67. tableView.delegate = self;
  68. tableView.dataSource = self;
  69. [self.view addSubview:tableView];
  70. tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  71. _myTable = tableView;
  72. }
  73. return _myTable;
  74. }
  75. #pragma mark----tableviewDelegate
  76. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  77. return _dataArray.count;
  78. }
  79. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  80. return 100;
  81. }
  82. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  83. static NSString *cellID = @"cell";
  84. DetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];;
  85. if (!cell) {
  86. cell = [[DetailTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
  87. }
  88. detatilDeviceModel *detail = [self.dataArray objectAtIndex:indexPath.row];
  89. cell.timeLabel.text=detail.inputtime;
  90. if ([detail.devicestatus isEqualToNumber:@(8)]||[detail.fireAlarm isEqualToNumber:@(1)]) {
  91. cell.stateLabel.text =@"状态:火警";
  92. cell.stateLabel.textColor = [UIColor redColor];
  93. cell.pointImg.image =[UIImage imageNamed:@"hsh_home_alert_point"];
  94. }else{
  95. cell.stateLabel.text =@"状态:正常";
  96. cell.stateLabel.textColor = [UIColor blueColor];
  97. cell.pointImg.image =[UIImage imageNamed:@"hsh_home_details_normal"];
  98. }
  99. cell.voltageLabel.text = [NSString stringWithFormat:@"当前电池电压:%@",detail.batteryVoltage];
  100. cell.signalLabel.text =[NSString stringWithFormat:@"信号强度:%@",detail.signalStrength];
  101. cell.tempLabel.text = [NSString stringWithFormat:@"CPU温度:%@",detail.mcuTemp];
  102. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  103. return cell;
  104. }
  105. //编辑单元格使用的方法
  106. -(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
  107. return UITableViewCellEditingStyleDelete | UITableViewCellEditingStyleInsert;
  108. }
  109. - (void)didReceiveMemoryWarning {
  110. [super didReceiveMemoryWarning];
  111. // Dispose of any resources that can be recreated.
  112. }
  113. /*
  114. #pragma mark - Navigation
  115. // In a storyboard-based application, you will often want to do a little preparation before navigation
  116. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  117. // Get the new view controller using [segue destinationViewController].
  118. // Pass the selected object to the new view controller.
  119. }
  120. */
  121. @end