// // RailListViewController.m // watch // // Created by xTT on 2017/7/13. // Copyright © 2017年 xTT. All rights reserved. // #import "RailListViewController.h" #import "AddRailViewController.h" #import "Rail.h" #import "RailListTableViewCell.h" #import "CommonPopView.h" #import "NewTrackVC.h" @interface RailListViewController () @end @implementation RailListViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.title = @"电子围栏"; self.myTableView.frame = CGRectMake(15, iPhoneX_NavHeight, ScreenWidth-30, ScreenHeight-iPhoneX_NavHeight); [self zx_setRightBtnWithText:@"添加" clickedBlock:^(ZXNavItemBtn * _Nonnull btn) { [self gpsSwitch]; }]; [self.myTableView registerClass:RailListTableViewCell.class forCellReuseIdentifier:NSStringFromClass(RailListTableViewCell.class)]; //去线 self.myTableView.separatorStyle = UITableViewCellSeparatorStyleNone; // self.myTableView.emptyDataSetSource = self; // self.myTableView.emptyDataSetDelegate = self; } - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; WEAKSELF [Rail getObjsSuccess:^(NSMutableArray *arr) { [weakSelf.myDataSource removeAllObjects]; [weakSelf.myDataSource addObjectsFromArray:arr]; [weakSelf.myTableView reloadData]; } failure:^(NSError *error){ if (!error) { } }]; self.buttonTitle = @"添加"; self.emptyTitle = @"未添加电子围栏"; self.buttonImg = [UICommon imageWithColor:mainColor size:CGSizeMake(ScreenWidth-60, 48)]; } - (void)emptyDataSetButton { [self gpsSwitch]; } /// 添加电子围栏之前,判断历史轨迹是否开启 - (void)gpsSwitch { if (cUser.cDevice.opGpsSwitch.boolValue) [self rightBarItemClick]; else { CommonPopView *popView = [CommonPopView new]; [popView subPopView:popViewType_dzwl PopTitle:@"温馨提示" PopText:@"使用电子围栏功能之前,需要开启历史轨迹" okTouchBlock:^{ [UICommon PusXibViewController:[NewTrackVC new] :@"NewTrackVC"]; }]; } } - (void)rightBarItemClick { // [self performSegueWithIdentifier:@"goRailVC" sender:nil]; UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; AddRailViewController *vc = [sb instantiateViewControllerWithIdentifier:@"AddRailViewController"]; vc.isAdd = YES; [self.navigationController pushViewController:vc animated:YES]; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 172; } -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return self.myDataSource.count; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return 1; } -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 12; } - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ // if ([[self.myDataSource firstObject] count] > 0) { // return @"地址"; // } return @""; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { Rail *rail = self.myDataSource[indexPath.section]; RailListTableViewCell *cell = [RailListTableViewCell cellWithTableView:tableView indexPath:indexPath]; cell.model = rail; WEAKSELF cell.editingBlock = ^{ UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; AddRailViewController *vc = [sb instantiateViewControllerWithIdentifier:@"AddRailViewController"]; vc.isAdd = NO; vc.infoRail = rail; [weakSelf.navigationController pushViewController:vc animated:YES]; }; cell.deleteBlock = ^{ [weakSelf viewWillAppear:YES]; }; cell.switchBlock = ^{ [UICommon MessageSuccessText:@"修改状态成功" isImg:YES]; [weakSelf.myTableView reloadData]; }; return cell; } - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{ return UITableViewCellEditingStyleNone; } - (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. [segue.destinationViewController setValue:sender forKey:@"infoRail"]; } @end