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.
173 lines
5.8 KiB
173 lines
5.8 KiB
// |
|
// AddVAViewController.m |
|
// watch |
|
// |
|
// Created by xTT on 2017/7/15. |
|
// Copyright © 2017年 xTT. All rights reserved. |
|
// |
|
|
|
#import "AddVAViewController.h" |
|
#import "AddWeekTableViewCell.h" |
|
#import "RecordingBtn.h" |
|
#import "XHAudioPlayerHelper.h" |
|
|
|
#import "SelectWeekViewController.h" |
|
|
|
@interface AddVAViewController () |
|
|
|
@end |
|
|
|
@implementation AddVAViewController |
|
|
|
@synthesize myDataSource = _myDataSource; |
|
|
|
- (NSMutableArray *)myDataSource{ |
|
if (!_myDataSource) { |
|
_myDataSource = [[NSMutableArray alloc] initWithArray:@[@[@"标签",@"时间",@"星期"]]]; |
|
} |
|
return _myDataSource; |
|
} |
|
|
|
- (VoiceAlarm *)infoVoiceAlarm{ |
|
if (!_infoVoiceAlarm) { |
|
_infoVoiceAlarm = [[VoiceAlarm alloc] init]; |
|
[_infoVoiceAlarm setDefaultValue]; |
|
} |
|
return _infoVoiceAlarm; |
|
} |
|
|
|
-(void)viewWillAppear:(BOOL)animated{ |
|
[super viewWillAppear:animated]; |
|
if (!self.isAdd) { |
|
self.title = @"添加闹钟"; |
|
}else{ |
|
self.title = @"编辑闹钟"; |
|
} |
|
} |
|
- (void)viewDidLoad { |
|
[super viewDidLoad]; |
|
// Do any additional setup after loading the view. |
|
|
|
[self zx_setRightBtnWithText:@"保存" clickedBlock:^(ZXNavItemBtn * _Nonnull btn) { |
|
[self rightBarItemClick]; |
|
}]; |
|
[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); |
|
}]; |
|
|
|
// RecordingBtn *recordingBtn = [[RecordingBtn alloc] initWithFrame: CGRectMake(0, 0, 80, 80)]; |
|
// recordingBtn.center = CGPointMake(self.view.center.x, SHEIGHT - 120); |
|
// [recordingBtn initCellView:nil]; |
|
// |
|
// [self.view addSubview:recordingBtn]; |
|
// |
|
// WEAKSELF |
|
// recordingBtn.block = ^(NSDictionary *recordDic){ |
|
// [weakSelf.infoVoiceAlarm mj_setKeyValues:recordDic]; |
|
// [weakSelf.myTableView reloadData]; |
|
// }; |
|
|
|
//注册cell |
|
|
|
[self.myTableView registerNib:[UINib nibWithNibName:@"AddWeekTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"AddWeekTableViewCellID"]; |
|
} |
|
|
|
- (void)viewWillDisappear:(BOOL)animated{ |
|
[super viewWillDisappear:animated]; |
|
[[XHAudioPlayerHelper shareInstance] pausePlayingAudio]; |
|
} |
|
|
|
- (void)rightBarItemClick |
|
{ |
|
if (self.infoVoiceAlarm.text.length > 8) { |
|
[SVProgressHUD showErrorWithStatus:@"标签为8位字符内"]; |
|
}else{ |
|
// if (!self.infoVoiceAlarm.id && !self.infoVoiceAlarm.voicePath) { |
|
// [SVProgressHUD showErrorWithStatus:@"未录音,请按下录音按钮说话"]; |
|
// }else{ |
|
[self.view endEditing:YES]; |
|
[self.infoVoiceAlarm saveSuccess:^{ |
|
[self goBack:nil]; |
|
} failure:^{}]; |
|
// } |
|
} |
|
} |
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ |
|
NSString *title = self.myDataSource[indexPath.section][indexPath.row]; |
|
if ([title isEqualToString:@"星期"]) { |
|
|
|
AddWeekTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AddWeekTableViewCellID" forIndexPath:indexPath]; |
|
// cell.aTitleLabel.text = title; |
|
cell.textLabel.text = title; |
|
cell.textLabel.font = DefineFontSize; |
|
[cell setWeek:self.infoVoiceAlarm.week]; |
|
WEAKSELF |
|
cell.weekSelectBlack = ^(NSString *selectWeek) { |
|
weakSelf.infoVoiceAlarm.week = selectWeek; |
|
}; |
|
cell.accessoryType = UITableViewCellAccessoryNone; |
|
|
|
return cell; |
|
}else if([title isEqualToString:@"时间"] || [title isEqualToString:@"标签"]){ |
|
TextFieldCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TextFieldCell"]; |
|
if (!cell) { |
|
cell = [[TextFieldCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"TextFieldCell"]; |
|
|
|
} |
|
cell.textLabel.text = title; |
|
if ([title isEqualToString:@"时间"]) { |
|
NSDateFormatter * df = [[NSDateFormatter alloc]init]; |
|
[df setDateFormat:@"HH:mm"]; |
|
[cell timeInputViewWithModel:UIDatePickerModeTime WithData:[df dateFromString:self.infoVoiceAlarm.time]]; |
|
cell.textField.text = self.infoVoiceAlarm.time; |
|
cell.textField.tintColor = [UIColor clearColor]; //使光标不可见 |
|
cell.textField.font = DefineFontSize; |
|
cell.accessoryType = UITableViewCellAccessoryNone; |
|
}else if([title isEqualToString:@"标签"]){ |
|
cell.maxLimitLength = 8; |
|
cell.textField.textAlignment = NSTextAlignmentRight; |
|
cell.textField.text = self.infoVoiceAlarm.text; |
|
} |
|
|
|
WEAKSELF |
|
cell.block = ^(NSString *text, TextFieldCell *blockCell){ |
|
if ([title isEqualToString:@"时间"]) { |
|
weakSelf.infoVoiceAlarm.time = text; |
|
}else if([title isEqualToString:@"标签"]){ |
|
self.infoVoiceAlarm.text = text; |
|
} |
|
}; |
|
return cell; |
|
} |
|
|
|
return nil; |
|
} |
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ |
|
// NSString *text = self.myDataSource[indexPath.section][indexPath.row]; |
|
// if ([text isEqualToString:@"星期"]) { |
|
// SelectWeekViewController *vc = [[SelectWeekViewController alloc] init]; |
|
// vc.model = self.infoVoiceAlarm; |
|
// [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. |
|
} |
|
*/ |
|
|
|
@end
|
|
|