仿IOS通讯录效果,实现获取手机通讯录、字母排序显示、搜索联系人、拨打电话

本文介绍了如何在iOS应用中实现通讯录效果,包括使用UITableView进行联系人字母排序,利用UISearchController实现搜索功能,展示联系人信息,并通过自定义alertView展示详细信息及拨打电话。同时,还提供了获取手机联系人的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.使用UITableView,实现联系人字母排序、点击字母跳转显示联系人组目录;

2.使用UISearchController,实现联系搜索,动态显示符合查询的联系人;

3.点击通讯录列表项,显示联系人信息(使用自定义模式化窗口类似与UIAlertView,使用UIwindow实现),点击拨号,可以直接拨打电话;

4.实现获取手机通讯录里面的联系人信息;

详情见资源:http://download.youkuaiyun.com/detail/u011622479/9505751

效果图如下:

获取联系人:

           

搜索页:


                         


联系人信息:




主要显示页面代码:

//
//  ViewController.m
//  ContactionView
//
//  Created by rong xiang on 16/4/26.
//  Copyright © 2016年 hzz. All rights reserved.
//

#import "ViewController.h"
#import <AddressBook/AddressBook.h>
#import "MobileAddressBook.h"
#import "ChineseString.h"
#import "CustomAlertView.h"
#import "MyButton.h"

@interface ViewController (){
    NSMutableArray * listSection;
    NSMutableArray * addressBookTemp;
    NSMutableArray * listPhone;
    NSMutableArray *_searchContacts;//符合条件的搜索联系人
    CustomAlertView * alertView;
    
    UITableView *tableViewAddress;
    UISearchBar * _searchBar;
    UISearchDisplayController *_searchDisplayController;
}

@end

@implementation ViewController

-(void) loadView{
    [super loadView];
    
    tableViewAddress = [[UITableView alloc] initWithFrame:CGRectMake(0, 20, self.view.frame.size.width, self.view.frame.size.height - 20)];
    [tableViewAddress setBackgroundColor:[UIColor colorWithRed:250.0f/255.0f green:250.0f/255.0f blue:250.0f/255.0f alpha:1.0]];
    [tableViewAddress setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [self.view addSubview:tableViewAddress];
    
       [self addSearchBar];

}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //初始化显示对象
    addressBookTemp = [[NSMutableArray alloc] init];
    listSection = [[NSMutableArray alloc] init];
    listPhone =[[NSMutableArray alloc] init];
    NSMutableArray * listPhoneShow = [[NSMutableArray alloc] init];
    
    tableViewAddress.delegate = self;
    tableViewAddress.dataSource = self;
    //获取通讯录联系人信息
    [self getAddressBook];
    //测试下的:初始化列表数据
    [self initData];
    //获取通讯录列表首字母,并排序
    listSection = [ChineseString IndexArray:addressBookTemp];
    //获取通讯录,并把通讯录对象按照首字母进行分组排序
    listPhoneShow = [ChineseString LetterSortArray:addressBookTemp];
    //把对应的同一个首字母下联系人对象按照首字母排序列表进行分组;
    NSInteger count = [listPhoneShow count];
    NSArray * array = nil;
    
    
    for(int i =0;i<count;i++){
        
        array =[listPhoneShow objectAtIndex:i];
        
        NSInteger arrCount = [array count];
        NSMutableArray * showArr = [[NSMutableArray alloc] init];
        
        for(int j =0;j< arrCount;j++){
            
            NSString *tempStr = [array objectAtIndex:j];
            
            for(MobileAddressBook * add in addressBookTemp){
                
                if([[add name] isEqualToString:tempStr]){
                    add.firstName = [listSection objectAtIndex:i];
                    [showArr addObject:add];
                    break;
                }
                
            }
            
        }
        [listPhone addObject:showArr];
    }

}

-(void) dealloc{
    
    tableViewAddress.dataSource = nil;
    tableViewAddress.delegate = nil;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark 搜索形成新数据
-(void)searchDataWithKeyWord:(NSString *)keyWord{
    //_isSearching=YES;
    _searchContacts=[NSMutableArray array];
    
  int count =  [listPhone count];
    int arrCount = 0;
    NSArray * arr  = nil;
    MobileAddressBook * contact = nil;
    //过滤
    for(int i=0;i<count;i++){
        arr = [listPhone objectAtIndex:i];
        arrCount = arr.count;
        
        for(int j=0;j<arrCount;j++){
            contact = [arr objectAtIndex:j];
            if ([contact.firstName.uppercaseString containsString:keyWord.uppercaseString]||[contact.name.uppercaseString containsString:keyWord.uppercaseString]||[contact.tel containsString:keyWord]) {
                [_searchContacts addObject:contact];
            }
            
        }
    }
    
//    [listPhone enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
//        NSArray * arr =obj;
//        [arr enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
//            MobileAddressBook * contact = obj;
//            if ([contact.firstName.uppercaseString containsString:keyWord.uppercaseString]|
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值