|
|
|
//
|
|
|
|
// AddContactsViewController.m
|
|
|
|
// watch
|
|
|
|
//
|
|
|
|
// Created by xTT on 2017/7/15.
|
|
|
|
// Copyright © 2017年 xTT. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "AddContactsViewController.h"
|
|
|
|
|
|
|
|
@interface AddContactsViewController ()
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation AddContactsViewController
|
|
|
|
|
|
|
|
@synthesize myDataSource = _myDataSource;
|
|
|
|
|
|
|
|
- (NSMutableArray *)myDataSource{
|
|
|
|
if (!_myDataSource) {
|
|
|
|
_myDataSource = [[NSMutableArray alloc] initWithArray:@[@[@"昵称",@"号码"]]];
|
|
|
|
}
|
|
|
|
return _myDataSource;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (Contacts *)infoContacts{
|
|
|
|
if (!_infoContacts) {
|
|
|
|
_infoContacts = [[Contacts alloc] init];
|
|
|
|
[_infoContacts setDefaultValue];
|
|
|
|
}
|
|
|
|
return _infoContacts;
|
|
|
|
}
|
|
|
|
-(void)viewWillAppear:(BOOL)animated
|
|
|
|
{
|
|
|
|
[super viewWillAppear:animated];
|
|
|
|
if([self.infoContacts.phone isEqualToString:@""] && [self.infoContacts.name isEqualToString:@""]){
|
|
|
|
self.title = @"添加联系人";
|
|
|
|
}else{
|
|
|
|
self.title = @"修改联系人";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
- (void)viewDidLoad {
|
|
|
|
[super viewDidLoad];
|
|
|
|
// Do any additional setup after loading the view.
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)rightBarItemClick:(UIBarButtonItem *)sender{
|
|
|
|
if (self.infoContacts.name.length == 0) {
|
|
|
|
[UICommon MessageErrorText:@"请输入昵称"];
|
|
|
|
}else if (self.infoContacts.name.length > 8) {
|
|
|
|
[UICommon MessageErrorText:@"昵称为8位字符内"];
|
|
|
|
}else if (self.infoContacts.phone.length < 3 || self.infoContacts.phone.length > 15){
|
|
|
|
[UICommon MessageErrorText:@"号码为3~15位"];
|
|
|
|
}else{
|
|
|
|
[self.infoContacts saveSuccess:^{
|
|
|
|
[self goBack:nil];
|
|
|
|
} failure:^{}];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
|
|
|
|
TextFieldCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TextFieldCell"];
|
|
|
|
if (!cell) {
|
|
|
|
cell = [[TextFieldCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"TextFieldCell"];
|
|
|
|
cell.accessoryType = UITableViewCellAccessoryNone;
|
|
|
|
}
|
|
|
|
cell.textLabel.text = self.myDataSource[indexPath.section][indexPath.row];
|
|
|
|
if ([cell.textLabel.text isEqualToString:@"昵称"]) {
|
|
|
|
cell.textField.text = self.infoContacts.name;
|
|
|
|
cell.textField.placeholder = @"8位字符内";
|
|
|
|
}else if ([cell.textLabel.text isEqualToString:@"号码"]){
|
|
|
|
cell.textField.keyboardType = UIKeyboardTypePhonePad;
|
|
|
|
cell.textField.text = self.infoContacts.phone;
|
|
|
|
cell.textField.placeholder = @"长号或短号号码";
|
|
|
|
}
|
|
|
|
|
|
|
|
WEAKSELF
|
|
|
|
cell.block = ^(NSString *text, TextFieldCell *blockCell){
|
|
|
|
if ([blockCell.textLabel.text isEqualToString:@"昵称"]) {
|
|
|
|
weakSelf.infoContacts.name = text;
|
|
|
|
}else if ([blockCell.textLabel.text isEqualToString:@"号码"]){
|
|
|
|
weakSelf.infoContacts.phone = text;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
|
|
|
|
if (section == self.myDataSource.count - 1) {
|
|
|
|
return 10 + 70 + 10;
|
|
|
|
}
|
|
|
|
return [super tableView:tableView heightForFooterInSection:section];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
|
|
|
|
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
|
|
|
|
if (!self.infoContacts.id && section == self.myDataSource.count - 1) {
|
|
|
|
UILabel *lable = [[UILabel alloc] initWithFrame:CGRectMake((SWIDTH - 310 * FIX_SCREEN) / 2, 10 ,
|
|
|
|
310 * FIX_SCREEN, 70)];
|
|
|
|
lable.text = @"1.请为设备添加联系人号码,设备才能给您打电话\n2.如果您与设备sim卡号码开通了短号功能,需将您的短号加入设备电话本中";
|
|
|
|
lable.numberOfLines = 0;
|
|
|
|
lable.font = [UIFont systemFontOfSize:14];
|
|
|
|
lable.textColor = [UIColor lightGrayColor];
|
|
|
|
[view addSubview:lable];
|
|
|
|
}
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (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
|