DetailDeveceList_VC.m 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. //
  2. // DetailDeveceList_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 "DetailDeveceList_VC.h"
  9. #import "DeveceTableCell.h"
  10. #import "deveceListModel.h"
  11. @interface DetailDeveceList_VC ()<UITableViewDelegate,UITableViewDataSource>
  12. @property (nonatomic,strong)UITableView *myTable;
  13. @end
  14. @implementation DetailDeveceList_VC
  15. -(void)viewWillAppear:(BOOL)animated{
  16. [super viewWillAppear:animated];
  17. }
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. // Do any additional setup after loading the view.
  21. self.navigationItem.title = @"设备列表";
  22. self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:60/255.0 green:114/255.0 blue:255/255.0 alpha:1];
  23. [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:18],NSForegroundColorAttributeName:[UIColor whiteColor]}];
  24. UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  25. [backBtn setImage:[UIImage imageNamed:@"hsh_return"] forState:UIControlStateNormal];
  26. backBtn.frame = CGRectMake(0, 0, 44, 44);
  27. [backBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
  28. backBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  29. self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backBtn];
  30. self.view.backgroundColor = [UIColor whiteColor];
  31. [self setupUI];
  32. [DataSourceManager getDeveceWithUrlPagesize:100 SiteId:_siteID Page:1 completionBlock:^(NSMutableArray *array) {
  33. _dataArray = array;
  34. [_myTable reloadData];
  35. }];
  36. }
  37. -(void)backClick{
  38. [self.navigationController popViewControllerAnimated:YES];
  39. }
  40. -(void)setupUI{
  41. self.myTable.frame = CGRectMake(0, 0, WIDTH, HEIGHT);
  42. self.myTable.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  43. [self.view addSubview:_myTable];
  44. }
  45. -(UITableView *)myTable{
  46. if (!_myTable) {
  47. UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, WIDTH, HEIGHT-64-49) style:UITableViewStylePlain];
  48. tableView.delegate = self;
  49. tableView.dataSource = self;
  50. [self.view addSubview:tableView];
  51. _myTable = tableView;
  52. }
  53. return _myTable;
  54. }
  55. #pragma mark----tableviewDelegate
  56. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  57. return self.dataArray.count;
  58. }
  59. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  60. return 70;
  61. }
  62. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  63. static NSString *cellID = @"cell";
  64. DeveceTableCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];;
  65. if (!cell) {
  66. cell = [[DeveceTableCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
  67. }
  68. NSLog(@"------>%@",self.dataArray);
  69. deveceListModel *list =[self.dataArray objectAtIndex:indexPath.row];
  70. cell.nameLabel.text = list.deviceName;
  71. cell.nameLabel.numberOfLines =0;
  72. cell.nameLabel.lineBreakMode = NSLineBreakByWordWrapping;
  73. cell.numberLabel.text = list.deviceId;
  74. cell.numberLabel.numberOfLines =0;
  75. cell.numberLabel.lineBreakMode = NSLineBreakByWordWrapping;
  76. cell.locationLabel.text = list.deviceLocation;
  77. if ([list.troubleType isEqualToString:@"0"]) {
  78. cell.stateLabel.text = @"故障";
  79. cell.stateLabel.textColor = [UIColor orangeColor];
  80. }else if ([list.troubleType isEqualToString:@"1"]){
  81. cell.stateLabel.text = @"火警";
  82. cell.stateLabel.textColor = [UIColor redColor];
  83. }else{
  84. cell.stateLabel.text = @"正常";
  85. cell.stateLabel.textColor = [UIColor blueColor];
  86. }
  87. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  88. // cell.titleLabel.动态设置
  89. return cell;
  90. }
  91. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  92. deveceListModel *list =[self.dataArray objectAtIndex:indexPath.row];
  93. DeveceDetail_VC *deve = [[DeveceDetail_VC alloc]init];
  94. deve.deviceName = list.deviceName;
  95. deve.location =list.deviceLocation;
  96. deve.deveceID =list.deviceId;
  97. deve.d_location = list.deviceLocation;
  98. deve.hidesBottomBarWhenPushed =YES;
  99. [self.navigationController pushViewController:deve animated:YES];
  100. }
  101. #pragma mark ---->左滑删除和详情
  102. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
  103. return YES;
  104. }
  105. - (nullable NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(8_0) __TVOS_PROHIBITED{
  106. // 添加一个删除按钮
  107. UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"删除"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  108. deveceListModel *list =[self.dataArray objectAtIndex:indexPath.row];
  109. NSString *deveceID = list.deviceId;
  110. //在这里添加点击事件
  111. [DataSourceManager deleteDeveceWithUrlDeveceId:deveceID completionBlock:^(NSDictionary *dic) {
  112. // 删除数据源
  113. [self.dataArray removeObjectAtIndex:indexPath.row];
  114. [_myTable reloadData];
  115. //或者cell删除
  116. // [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
  117. }];
  118. // 刷新数据
  119. }];
  120. // 添加一个编辑按钮
  121. UITableViewRowAction *topRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"详情"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  122. deveceListModel *list =[self.dataArray objectAtIndex:indexPath.row];
  123. DeveceDetail_VC *deve = [[DeveceDetail_VC alloc]init];
  124. deve.deviceName = list.deviceName;
  125. // deve.location = list.lo;
  126. deve.deveceID =list.deviceId;
  127. deve.d_location = list.deviceLocation;
  128. deve.hidesBottomBarWhenPushed =YES;
  129. [self.navigationController pushViewController:deve animated:YES];
  130. }];
  131. topRowAction.backgroundColor = [UIColor blueColor];
  132. // 将设置好的按钮放到数组中返回
  133. return @[deleteRowAction, topRowAction];
  134. }
  135. - (void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath {
  136. NSLog(@"已经结束编辑cell");
  137. }
  138. - (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{
  139. //点击了详情按钮
  140. }
  141. - (void)didReceiveMemoryWarning {
  142. [super didReceiveMemoryWarning];
  143. // Dispose of any resources that can be recreated.
  144. }
  145. /*
  146. #pragma mark - Navigation
  147. // In a storyboard-based application, you will often want to do a little preparation before navigation
  148. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  149. // Get the new view controller using [segue destinationViewController].
  150. // Pass the selected object to the new view controller.
  151. }
  152. */
  153. @end