You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
4.3 KiB

//
// RailListViewController.m
// watch
//
// Created by xTT on 2017/7/13.
// Copyright © 2017xTT. All rights reserved.
//
#import "RailListViewController.h"
#import "AddRailViewController.h"
#import "Rail.h"
#import "RailListCell.h"
@interface RailListViewController ()
@end
@implementation RailListViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.title = @"电子围栏";
[self zx_setRightBtnWithText:@"添加" clickedBlock:^(ZXNavItemBtn * _Nonnull btn) {
[self rightBarItemClick];
}];
[self.myTableView registerNib:[UINib nibWithNibName:@"RailListCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"RailListCellID"];
//去线
self.myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.topImage mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.view);
make.top.equalTo(self.view).offset(iPhoneX_NavHeight);
make.height.mas_equalTo(self.topImage.image.size.height);
}];
}
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
WEAKSELF
[Rail getObjsSuccess:^(NSMutableArray *arr) {
[weakSelf.myDataSource removeAllObjects];
[weakSelf.myDataSource addObjectsFromArray:@[arr]];
[weakSelf.myTableView reloadData];
[weakSelf showNoDataSourceView];
} failure:^(NSError *error){
if (!error) {
[weakSelf showNoReachableView];
}
}];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gotoAddRailViewController)];
[self.noDataSourceImageView addGestureRecognizer:tapGesture];
self.noDataSourceImageView.userInteractionEnabled = YES;
}
- (void)gotoAddRailViewController {
[self rightBarItemClick];
}
- (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 125+10;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
// if ([[self.myDataSource firstObject] count] > 0) {
// return 30;
// }
return 0.1;
}
- (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][indexPath.row];
RailListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RailListCellID" forIndexPath: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 = ^{
[SVProgressHUD showSuccessWithStatus:@"修改状态成功"];
};
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