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.
 
 
 
 

140 lines
5.2 KiB

//
// DisturbBanViewController.m
// watch
//
// Created by xTT on 2017/7/12.
// Copyright © 2017年 xTT. All rights reserved.
//
#import "DisturbBanViewController.h"
#import "AddDBViewController.h"
#import "DisturbBan.h"
#import "MyUILabel.h"
@interface DisturbBanViewController ()
@end
@implementation DisturbBanViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.zx_navTitle = @"上课禁用";
[self zx_setRightBtnWithText:@"添加" clickedBlock:^(ZXNavItemBtn * _Nonnull btn) {
[self performSegueWithIdentifier:@"goAddDisturbBanVC" sender:nil];
}];
[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);
}];
// [self.myTableView mas_remakeConstraints:^(MASConstraintMaker *make) {
// make.left.right.equalTo(self.view);
// make.top.equalTo(self.view).offset(iPhoneX_NavHeight);
// make.bottom.equalTo(self.view.mas_bottom);
// }];
}
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
WEAKSELF
[DisturbBan getObjsSuccess:^(NSMutableArray *arr)
{
[weakSelf.myDataSource removeAllObjects];
[weakSelf.myDataSource addObjectsFromArray:@[arr]];
[weakSelf.myTableView reloadData];
[weakSelf showNoDataSourceView];
// add by lsz
MyUILabel *header = [[MyUILabel alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 72)];
header.font =[UIFont systemFontOfSize:14];
header.adjustsFontSizeToFitWidth = YES;
header.numberOfLines = 3;
header.baselineAdjustment = UIBaselineAdjustmentAlignCenters;
[header setTextColor:[UIColor systemGrayColor]];
[header setText:@"温馨提示:\n禁用时设备除可以呼出SOS号码外,设备仅可查看时间,同时拒接所有电话和消息."];
weakSelf.myTableView.tableHeaderView = header;
} failure:^(NSError *error){
if (!error) {
[weakSelf showNoReachableView];
}
}];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gotoAddDisturbBanVC)];
[self.noDataSourceImageView addGestureRecognizer:tapGesture];
self.noDataSourceImageView.userInteractionEnabled = YES;
}
- (void)gotoAddDisturbBanVC
{
[self performSegueWithIdentifier:@"goAddDisturbBanVC" sender:nil];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 75;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
baseCell *cell = [tableView dequeueReusableCellWithIdentifier:@"baseCell"];
DisturbBan *disturbBan = self.myDataSource[indexPath.section][indexPath.row];
if (!cell) {
cell = [[baseCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"baseCell"];
cell.textLabel.font = [myHelper fixFoneSize:20 font:cell.textLabel.font];
cell.detailTextLabel.font = [myHelper fixFoneSize:15 font:cell.detailTextLabel.font];
UISwitch *uiSwitch = [[UISwitch alloc] init];
cell.accessoryView = uiSwitch;
[uiSwitch addTarget:cell
action:@selector(cellClick:)
forControlEvents:UIControlEventValueChanged];
}
UISwitch *uiSwitch = (UISwitch *)cell.accessoryView;
uiSwitch.on = [disturbBan.status boolValue];
cell.textLabel.text = [NSString stringWithFormat:@"%@-%@",disturbBan.starttime,disturbBan.endedtime];
cell.detailTextLabel.text = [myHelper getWeekDayStr:[disturbBan week]];
cell.block = ^(UISwitch *uiSwitch, baseCell *blockCell){
disturbBan.status = @(uiSwitch.on);
[disturbBan saveSuccess:^{}
failure:^{
uiSwitch.on = !uiSwitch.on;
disturbBan.status = @(uiSwitch.on);
}];
};
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
DisturbBan *disturbBan = self.myDataSource[indexPath.section][indexPath.row];
// [self performSegueWithIdentifier:@"goAddDisturbBanVC" sender:disturbBan];
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
AddDBViewController *vc = [sb instantiateViewControllerWithIdentifier:@"AddDBViewController"];
vc.isAdd = YES;
vc.infoDisturBan = disturbBan;
[self.navigationController pushViewController:vc 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.
if (sender) {
[segue.destinationViewController setValue:sender forKey:@"infoDisturBan"];
}
}
@end