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.
134 lines
4.6 KiB
134 lines
4.6 KiB
![]()
2 years ago
|
//
|
||
|
// VoiceAlarmViewController.m
|
||
|
// watch
|
||
|
//
|
||
|
// Created by xTT on 2017/7/12.
|
||
|
// Copyright © 2017年 xTT. All rights reserved.
|
||
|
//
|
||
|
|
||
|
#import "VoiceAlarmViewController.h"
|
||
|
#import "AddVAViewController.h"
|
||
|
#import "VoiceAlarm.h"
|
||
|
|
||
|
@interface VoiceAlarmViewController ()
|
||
|
|
||
|
@end
|
||
|
|
||
|
@implementation VoiceAlarmViewController
|
||
|
|
||
|
- (void)viewDidLoad {
|
||
|
[super viewDidLoad];
|
||
|
// Do any additional setup after loading the view.
|
||
|
self.zx_navTitle = @"设备闹钟";
|
||
|
[self zx_setRightBtnWithText:@"添加" clickedBlock:^(ZXNavItemBtn * _Nonnull btn) {
|
||
|
[self performSegueWithIdentifier:@"goAddVoiceAlarmVC" sender:nil];
|
||
|
}];
|
||
|
|
||
|
self.topImage.backgroundColor = KKGrey143;
|
||
|
[self.topImage mas_updateConstraints:^(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
|
||
|
[VoiceAlarm 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(gotoAddVoiceAlarmVC)];
|
||
|
[self.noDataSourceImageView addGestureRecognizer:tapGesture];
|
||
|
self.noDataSourceImageView.userInteractionEnabled = YES;
|
||
|
}
|
||
|
|
||
|
- (void)gotoAddVoiceAlarmVC
|
||
|
{
|
||
|
[self performSegueWithIdentifier:@"goAddVoiceAlarmVC" sender:nil];
|
||
|
}
|
||
|
|
||
|
- (IBAction)rightBarItemClick:(UIBarButtonItem *)sender{
|
||
|
|
||
|
}
|
||
|
|
||
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
|
||
|
return 85;
|
||
|
}
|
||
|
|
||
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
|
||
|
baseCell *cell = [tableView dequeueReusableCellWithIdentifier:@"baseCell"];
|
||
|
VoiceAlarm *voiceAlarm = 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];
|
||
|
cell.detailTextLabel.adjustsFontSizeToFitWidth = YES;
|
||
|
cell.detailTextLabel.numberOfLines = 2;
|
||
|
|
||
|
UISwitch *uiSwitch = [[UISwitch alloc] init];
|
||
|
cell.accessoryView = uiSwitch;
|
||
|
[uiSwitch addTarget:cell
|
||
|
action:@selector(cellClick:)
|
||
|
forControlEvents:UIControlEventValueChanged];
|
||
|
|
||
|
}
|
||
|
UISwitch *uiSwitch = (UISwitch *)cell.accessoryView;
|
||
|
uiSwitch.onTintColor = mainColor;
|
||
|
uiSwitch.on = [voiceAlarm.status boolValue];
|
||
|
cell.textLabel.text = voiceAlarm.time;
|
||
|
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ , %@",voiceAlarm.text,[myHelper getWeekDayStr:[voiceAlarm week]]];
|
||
|
|
||
|
cell.block = ^(UISwitch *uiSwitch, TextFieldCell *blockCell){
|
||
|
voiceAlarm.status = @(uiSwitch.on);
|
||
|
[voiceAlarm saveSuccess:^{}
|
||
|
failure:^{
|
||
|
uiSwitch.on = !uiSwitch.on;
|
||
|
voiceAlarm.status = @(uiSwitch.on);
|
||
|
}];
|
||
|
};
|
||
|
|
||
|
return cell;
|
||
|
}
|
||
|
|
||
|
|
||
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
|
||
|
VoiceAlarm *voiceAlarm = self.myDataSource[indexPath.section][indexPath.row];
|
||
|
// [self performSegueWithIdentifier:@"goAddVoiceAlarmVC" sender:voiceAlarm];
|
||
|
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
|
||
|
AddVAViewController *vc = [sb instantiateViewControllerWithIdentifier:@"AddVAViewController"];
|
||
|
vc.isAdd = YES;
|
||
|
vc.infoVoiceAlarm = voiceAlarm;
|
||
|
[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:@"infoVoiceAlarm"];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@end
|