| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244 |
- //
- // Contacts_VC.m
- // Haishenghai-master
- //
- // Created by GG on 2019/1/5.
- // Copyright © 2019年 Haishenghai intelligence network technology. All rights reserved.
- //
- #import "Contacts_VC.h"
- #import "CustomAlertView.h"
- #import "Header.h"
- #import "PersonCell.h"
- #import <AddressBookUI/ABPeoplePickerNavigationController.h>
- #import <AddressBook/ABPerson.h>
- #import <AddressBookUI/ABPersonViewController.h>
- @interface Contacts_VC ()<UITableViewDelegate,UITableViewDataSource,ABPeoplePickerNavigationControllerDelegate,UITextFieldDelegate>
- @property (nonatomic,strong)UIView *headerView;
- @property (nonatomic,strong)UITableView *myTable;
- @property (nonatomic,strong)UITextField *textName;
- @property (nonatomic,strong)UITextField *textPhone;
- @property (nonatomic,strong)NSMutableArray *dataArray;
- @property (nonatomic,assign)NSInteger selectedId;
- @end
- @implementation Contacts_VC
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- self.view.backgroundColor = [UIColor whiteColor];
- self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:60/255.0 green:114/255.0 blue:255/255.0 alpha:1];
- [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:18],NSForegroundColorAttributeName:[UIColor whiteColor]}];
- //设置导航栏左侧按钮
- UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [backBtn setImage:[UIImage imageNamed:@"hsh_return"] forState:UIControlStateNormal];
- backBtn.frame = CGRectMake(0, 0, 44, 44);
- [backBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
- backBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
- self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backBtn];
-
- self.navigationItem.title =@"联系人";
- [self setupUI];
- //获取联系人 为null报错
- NSLog(@"这是联系人要穿的场所ID%@",_SiteId);
- [DataSourceManager getlinkmanWithUrlSiteId:_SiteId completionBlock:^(NSMutableArray *array) {
- _dataArray =array;
- NSLog(@"%@---->",array);
- [_myTable reloadData];
- }];
- //
- //集成下拉刷新控件
- [self setupDownRefresh];
- }
- -(void)backClick{
- [self.navigationController popViewControllerAnimated:YES];
- }
- /**
- * 集成下拉刷新控件
- */
- - (void)setupDownRefresh
- {
-
- // 设置回调(一旦进入刷新状态,就调用target的action,也就是调用self的loadNewData方法)
- self.myTable.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewDatas)];
- //马上进入刷新状态
- [self.myTable.mj_header beginRefreshing];
- }
- -(void)loadNewDatas{
- _pageIndex =1;//默认加载第一页
- [self.dataArray removeAllObjects];
- //请求数据
- [DataSourceManager getlinkmanWithUrlSiteId:_SiteId completionBlock:^(NSMutableArray *array) {
- _dataArray =array;
- [_myTable reloadData];
- //结束刷新
- [self.myTable.mj_header endRefreshing];
- }];
- [self.myTable.mj_header endRefreshing];
- }
- //取消选择
- - (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker
- {
- [peoplePicker dismissViewControllerAnimated:YES completion:nil];
- }
- -(void)setupUI{
-
- UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
- rightButton.frame = CGRectMake(0, 0, 40, 40);
- [rightButton setImage:[UIImage imageNamed:@"hsh_home_add_white"] forState:UIControlStateNormal];
- [rightButton addTarget:self action:@selector(Click) forControlEvents:UIControlEventTouchUpInside];
- UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:rightButton];
- self.navigationItem.rightBarButtonItem = rightItem;
-
- _myTable = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT) style:UITableViewStylePlain];
- _myTable.delegate = self;
- _myTable.dataSource = self;
- [self.view addSubview:_myTable];
- _myTable.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
-
- }
- #pragma mark--EVENT--------
- -(void)Click{
- [[CustomAlertView sharedAlertView] showAlertViewWithConfirmAction:^(NSArray *inputText) {
- NSLog(@"输入内容:%@", inputText);
- NSString *name = [inputText objectAtIndex:0];
- NSString *phone = [inputText objectAtIndex:1];
- [DataSourceManager addlinkmanWithUrlSiteId:_SiteId Name:name Phone:phone completionBlock:^(NSDictionary *dic) {
- NSLog(@"这是联系人%@",dic);
-
- [DataSourceManager getlinkmanWithUrlSiteId:_SiteId completionBlock:^(NSMutableArray *array) {
- _dataArray =array;
- [_myTable reloadData];
- //结束刷新
- [self.myTable.mj_header endRefreshing];
-
- }];
- [self.myTable.mj_header endRefreshing];
-
- }];
- } andReloadAction:^{
-
- }];
- }
- -(void)popView{
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"添加联系人" message:nil preferredStyle:UIAlertControllerStyleAlert];
- [alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
-
- [self dismissViewControllerAnimated:YES completion:nil];
- }]];
- [alertController addAction:[UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- UITextField *nameTF = alertController.textFields.firstObject;
- UITextField *phoneTF = alertController.textFields.lastObject;
-
-
- }]];
- [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
- textField.delegate = self;
- textField.placeholder = @"请输入联系人姓名:";
-
- }];
- [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
- textField.delegate =self;
- textField.placeholder = @"请输入联系人手机号码:";
- textField.keyboardType = UIKeyboardTypeNumberPad;
- }];
- // [alertController addAction:[UIAlertAction actionWithTitle:@"访问通讯录" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- // NSLog(@"访问通讯录");
- // //初始化通讯录
- // ABPeoplePickerNavigationController *nav = [[ABPeoplePickerNavigationController alloc] init];
- // nav.peoplePickerDelegate = self;
- // // if(IOS8_OR_LATER){
- // // nav.predicateForSelectionOfPerson = [NSPredicate predicateWithValue:false];
- // // }
- // [self presentViewController:nav animated:YES completion:nil];
- //
- // }]];
- [self presentViewController:alertController animated:YES completion:nil];
- }
- #pragma mark----tableviewDelegate
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
- return _dataArray.count;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- return 44;
- }
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- static NSString *cellID = @"cell";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];;
- if (!cell) {
- cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
-
- }
- contactModel *contact = [self.dataArray objectAtIndex:indexPath.row];
- cell.textLabel.text = [NSString stringWithFormat:@"%@ : %@",contact.name,contact.phone];
- _selectedId = indexPath.row;
- cell.preservesSuperviewLayoutMargins = false;
- //添加删除按钮
- UIButton *deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- deleteBtn.frame = CGRectMake(WIDTH-54, 0, 44, 44);
- [deleteBtn setImage:[UIImage imageNamed:@"hsh_login_delete"] forState:UIControlStateNormal];
- [deleteBtn addTarget:self action:@selector(deleteBtnClick:) forControlEvents:UIControlEventTouchUpInside];
- [cell.contentView addSubview:deleteBtn];
-
-
- return cell;
- }
- //编辑单元格使用的方法
- -(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
- return UITableViewCellEditingStyleDelete | UITableViewCellEditingStyleInsert;
- }
- -(void)deleteBtnClick:(UIButton *)btn{
-
- contactModel *contact = [self.dataArray objectAtIndex:_selectedId];
- NSString *contactId = [NSString stringWithFormat:@"%@",contact.ID];
- [DataSourceManager deletelinkmanWithUrlId:contactId completionBlock:^(NSDictionary *dic) {
- //
- [self.dataArray removeObjectAtIndex:_selectedId];
- ALERTSHOW(@"删除成功");
- [_myTable reloadData];
- }];
- }
- -(BOOL)textFieldShouldReturn:(UITextField *)textField{
- [textField resignFirstResponder];
- return YES;
- }
- -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
- [self.view endEditing:YES];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- -(void)viewWillDisappear:(BOOL)animated{
- NSLog(@"----%@",_siteStr);
- NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:_siteStr,@"site", nil];
- [[NSNotificationCenter defaultCenter]postNotificationName:@"changeValue" object:nil userInfo:dic];
- }
- /*
- #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
|