| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 |
- //
- // PlaceList_VC.m
- // Haishenghai-master
- //
- // Created by GG on 2019/1/4.
- // Copyright © 2019年 Haishenghai intelligence network technology. All rights reserved.
- //
- #import "PlaceList_VC.h"
- #import "Header.h"
- @interface PlaceList_VC ()<UITableViewDelegate,UITableViewDataSource>
- {
- NSInteger _selectIndex;
- NSString *siteID;
- }
- @property(nonatomic,strong)NSMutableArray *dataArray;
- @property(nonatomic,strong)NSIndexPath *index;
- @property(nonatomic,assign)NSInteger indexNum;
- @end
- @implementation PlaceList_VC
- - (void)viewDidLoad {
- [super viewDidLoad];
- _dataArray = [NSMutableArray array];
- self.navigationItem.title = @"场所列表";
- [self setupUI];
-
- [DataSourceManager getSiteWithUrlPagesize:100 Page:1 completionBlock:^(NSMutableArray *array) {
-
- _dataArray = array;
- [_tableView reloadData];
- }];
- //集成下拉刷新控件
- [self setupDownRefresh];
- }
- /**
- * 集成下拉刷新控件
- */
- - (void)setupDownRefresh
- {
-
- // 设置回调(一旦进入刷新状态,就调用target的action,也就是调用self的loadNewData方法)
- self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewDatas)];
- //马上进入刷新状态
- [self.tableView.mj_header beginRefreshing];
- }
- -(void)loadNewDatas{
- // _pageIndex =1;//默认加载第一页
- [self.dataArray removeAllObjects];
- //请求数据
-
- [DataSourceManager getSiteWithUrlPagesize:100 Page:1 completionBlock:^(NSMutableArray *array) {
- _dataArray = array;
- [_tableView reloadData];
- //结束刷新
- [self.tableView.mj_header endRefreshing];
-
- }];
- }
- -(void)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];
-
- //
- // rightButton.frame = CGRectMake(0, 0, 22, 22);
- // [rightButton setImage:[UIImage imageNamed:@"hsh_user_detail"] forState:UIControlStateNormal];
- //// [rightButton setTitle:@"删除" forState:UIControlStateNormal];
- // [rightButton addTarget:self action:@selector(confirmBtnClick) forControlEvents:UIControlEventTouchUpInside];
- //// UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:rightButton];
- //// self.navigationItem.rightBarButtonItem = rightItem;
-
- _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT) style:UITableViewStylePlain];
- _tableView.delegate = self;
- _tableView.dataSource = self;
- [self.view addSubview:_tableView];
- _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
- }
- -(void)backClick{
- [self.navigationController popViewControllerAnimated:YES];
- }
- #pragma mark---tableviewDataSource
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
- return _dataArray.count;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- return 63;
- }
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- static NSString *celld = @"cell";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:celld];
- if (!cell) {
- cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:celld];
-
- }
- // UIView *backView = [[UIView alloc]init];
- // backView.tag =indexPath.row;
- // backView.frame = CGRectMake(60, 0, self.view.frame.size.width, 63);
- // UIGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(action:)];
- //
- // [backView addGestureRecognizer:tap];
- // [cell.contentView addSubview:backView];
-
- cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
- PlaceModel *model = [self.dataArray objectAtIndex:indexPath.row];
-
- cell.textLabel.text = model.deployment;
- cell.detailTextLabel.text = model.location;
-
- UIView *line = [[UIView alloc]init];
- line.frame = CGRectMake(0, 60, WIDTH, 3);
- line.backgroundColor = [UIColor colorWithRed:227/255.0 green:227/255.0 blue:227/255.0 alpha:1];
- [cell.contentView addSubview:line];
- //添加长按删除
- UILongPressGestureRecognizer *longPressGR = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(lpGR:)];
-
- //设定最小的长按时间 按不够这个时间不响应手势
-
- longPressGR.minimumPressDuration = 1;
-
- [cell.contentView addGestureRecognizer:longPressGR];
- return cell;
- }
- //判断表视图是否编辑的时候让跳转
- -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- PlaceModel *model = [self.dataArray objectAtIndex:indexPath.row];
- siteID = model.Id;
- _selectIndex =indexPath.row;
- PlaceDetail_VC *detailVC = [[PlaceDetail_VC alloc]init];
- detailVC.siteName =model.deployment;
- detailVC.titleRegionalism = model.regionName;
- detailVC.titleLocation = model.location;
- detailVC.siteID = model.Id;
- [self.navigationController pushViewController:detailVC animated:YES];
- }
- -(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
- return YES;
- }
- //选择编辑的方式,按照选择的方式对表进行处理
- -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
- if (editingStyle == UITableViewCellEditingStyleDelete) {
-
- }
- }
- - (nullable NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(8_0) __TVOS_PROHIBITED{
- // 添加一个删除按钮
- UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"删除"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
- PlaceModel *model = [self.dataArray objectAtIndex:indexPath.row];
-
- [DataSourceManager deleteSiteWithUrlSiteID:model.Id completionBlock:^(NSDictionary *dic) {
- // 删除数据源
- [self.dataArray removeObjectAtIndex:_selectIndex];
- // 或者cell删除
- // [tableView deleteRowsAtIndexPaths:@[_selectIndex] withRowAnimation:UITableViewRowAnimationAutomatic];
- [_tableView reloadData];
- }];
- }];
- return @[deleteRowAction];
- }
- //选择你要对表进行处理的方式 默认是删除方式
- -(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
- return UITableViewCellEditingStyleDelete | UITableViewCellEditingStyleInsert;
- }
- -(void)action:(UIGestureRecognizer *)recognizer{
- UITapGestureRecognizer *tap = (UITapGestureRecognizer *)recognizer;
- NSInteger tag = tap.view.tag;
- PlaceModel *model = [self.dataArray objectAtIndex:tag];
- siteID = model.Id;
- _selectIndex = tag;
-
- PlaceDetail_VC *detailVC = [[PlaceDetail_VC alloc]init];
- detailVC.siteName =model.deployment;
- detailVC.titleRegionalism = model.regionName;
- detailVC.titleLocation = model.location;
- detailVC.siteID = model.Id;
- [self.navigationController pushViewController:detailVC 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.
- }
- */
- -(void)confirmBtnClick{
- //可以得到此时你点击的哪一行
- self.tableView.allowsMultipleSelectionDuringEditing = YES;
- self.tableView.editing = !self.tableView.editing;
-
- }
- //实现手势对应的功能
- -(void)lpGR:(UILongPressGestureRecognizer *)lpGR
- {
- if (lpGR.state == UIGestureRecognizerStateBegan) {//手势开始
-
- CGPoint point = [lpGR locationInView:self.tableView];
-
- self.index = [self.tableView indexPathForRowAtPoint:point]; // 可以获取我们在哪个cell上长按
-
- self.indexNum = self.index.row;
-
- }
- if (lpGR.state == UIGestureRecognizerStateEnded)//手势结束
- {
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"是否删除" message:nil delegate:self cancelButtonTitle:@"确认" otherButtonTitles:@"取消", nil];
-
- [alert show];
- }
-
- }
- //提示框代理方法
- - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
- if (buttonIndex == 0) {
- NSLog(@"这是场所的id%@",siteID);
- //有问题
- [DataSourceManager deleteSiteWithUrlSiteID:siteID completionBlock:^(NSDictionary *dic) {
- // 删除数据源
- [self.dataArray removeObjectAtIndex:_selectIndex];
- // 或者cell删除
- // [tableView deleteRowsAtIndexPaths:@[_selectIndex] withRowAnimation:UITableViewRowAnimationAutomatic];
- [_tableView reloadData];
- }];
- // [self.dataArray removeObjectAtIndex:self.indexNum];
- }else{
- }
- }
- @end
|