// // DetailDeveceList_VC.m // Haishenghai-master // // Created by GG on 2019/1/4. // Copyright © 2019年 Haishenghai intelligence network technology. All rights reserved. // #import "DetailDeveceList_VC.h" #import "DeveceTableCell.h" #import "deveceListModel.h" @interface DetailDeveceList_VC () @property (nonatomic,strong)UITableView *myTable; @end @implementation DetailDeveceList_VC -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.navigationItem.title = @"设备列表"; 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.view.backgroundColor = [UIColor whiteColor]; [self setupUI]; [DataSourceManager getDeveceWithUrlPagesize:100 SiteId:_siteID Page:1 completionBlock:^(NSMutableArray *array) { _dataArray = array; [_myTable reloadData]; }]; } -(void)backClick{ [self.navigationController popViewControllerAnimated:YES]; } -(void)setupUI{ self.myTable.frame = CGRectMake(0, 0, WIDTH, HEIGHT); self.myTable.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; [self.view addSubview:_myTable]; } -(UITableView *)myTable{ if (!_myTable) { UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, WIDTH, HEIGHT-64-49) style:UITableViewStylePlain]; tableView.delegate = self; tableView.dataSource = self; [self.view addSubview:tableView]; _myTable = tableView; } return _myTable; } #pragma mark----tableviewDelegate -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.dataArray.count; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 70; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *cellID = @"cell"; DeveceTableCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];; if (!cell) { cell = [[DeveceTableCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID]; } NSLog(@"------>%@",self.dataArray); deveceListModel *list =[self.dataArray objectAtIndex:indexPath.row]; cell.nameLabel.text = list.deviceName; cell.nameLabel.numberOfLines =0; cell.nameLabel.lineBreakMode = NSLineBreakByWordWrapping; cell.numberLabel.text = list.deviceId; cell.numberLabel.numberOfLines =0; cell.numberLabel.lineBreakMode = NSLineBreakByWordWrapping; cell.locationLabel.text = list.deviceLocation; if ([list.troubleType isEqualToString:@"0"]) { cell.stateLabel.text = @"故障"; cell.stateLabel.textColor = [UIColor orangeColor]; }else if ([list.troubleType isEqualToString:@"1"]){ cell.stateLabel.text = @"火警"; cell.stateLabel.textColor = [UIColor redColor]; }else{ cell.stateLabel.text = @"正常"; cell.stateLabel.textColor = [UIColor blueColor]; } cell.selectionStyle = UITableViewCellSelectionStyleNone; // cell.titleLabel.动态设置 return cell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ deveceListModel *list =[self.dataArray objectAtIndex:indexPath.row]; DeveceDetail_VC *deve = [[DeveceDetail_VC alloc]init]; deve.deviceName = list.deviceName; deve.location =list.deviceLocation; deve.deveceID =list.deviceId; deve.d_location = list.deviceLocation; deve.hidesBottomBarWhenPushed =YES; [self.navigationController pushViewController:deve animated:YES]; } #pragma mark ---->左滑删除和详情 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{ return YES; } - (nullable NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(8_0) __TVOS_PROHIBITED{ // 添加一个删除按钮 UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"删除"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) { deveceListModel *list =[self.dataArray objectAtIndex:indexPath.row]; NSString *deveceID = list.deviceId; //在这里添加点击事件 [DataSourceManager deleteDeveceWithUrlDeveceId:deveceID completionBlock:^(NSDictionary *dic) { // 删除数据源 [self.dataArray removeObjectAtIndex:indexPath.row]; [_myTable reloadData]; //或者cell删除 // [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; }]; // 刷新数据 }]; // 添加一个编辑按钮 UITableViewRowAction *topRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"详情"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) { deveceListModel *list =[self.dataArray objectAtIndex:indexPath.row]; DeveceDetail_VC *deve = [[DeveceDetail_VC alloc]init]; deve.deviceName = list.deviceName; // deve.location = list.lo; deve.deveceID =list.deviceId; deve.d_location = list.deviceLocation; deve.hidesBottomBarWhenPushed =YES; [self.navigationController pushViewController:deve animated:YES]; }]; topRowAction.backgroundColor = [UIColor blueColor]; // 将设置好的按钮放到数组中返回 return @[deleteRowAction, topRowAction]; } - (void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"已经结束编辑cell"); } - (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{ //点击了详情按钮 } - (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