本文主要实现通讯录的部分功能(分组名、索引、分组的组名)等等功能:

废话不多说了,先上效果图:

在工程中需要导入一个plist文件,文件图如图:

工程目录文件如图:

工程程序如图所示:

RootTableViewController.h

#import <UIKit/UIKit.h>

@interface RootTableViewController : UITableViewController
@property(strong,nonatomic) NSDictionary *dic;
@property(strong,nonatomic) NSArray *arrkeys;
@end

RootTableViewController.m

#import "RootTableViewController.h"

@interface RootTableViewController ()

@end

@implementation RootTableViewController

- (void)viewDidLoad {
[super viewDidLoad];
NSString *path=[[NSBundle mainBundle] pathForResource:@"sortednames" ofType:@"plist"];
self.dic=[NSDictionary dictionaryWithContentsOfFile:path];
// NSLog(@"%@",self.dic);
// NSLog(@"%@",self.dic.allKeys); // 字典排序 字典的输出是无序的, 需要排序
self.arrkeys=[self.dic.allKeys sortedArrayUsingSelector:@selector(compare:)];
// NSLog(@"%@",self.arrkeys);
// 唯一标识符
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"reuseIdentifier"];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} #pragma mark - 每个组的数量 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return self.arrkeys.count;
} #pragma mark - 组数列表
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSString *key=self.arrkeys[section];
NSArray *tempArr=self.dic[key];
// NSLog(@"%@",key);
return tempArr.count;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuseIdentifier" forIndexPath:indexPath]; NSString *key=self.arrkeys[indexPath.section];
NSArray *tempArr=self.dic[key];
NSString *name=tempArr[indexPath.row]; cell.textLabel.text=name; return cell;
} #pragma mark - 返回行高的方法
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return ;
} #pragma mark - 系统默认的开头关键字
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return self.arrkeys[section]; // return [NSString stringWithFormat:@"%c",(char)('A'+section)]; } #pragma mark - 自定义自体大小的开头关键字
-(UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UILabel *lbl=[[UILabel alloc] init]; lbl.backgroundColor=[UIColor redColor];
lbl.tintColor=[UIColor yellowColor];
lbl.text=self.arrkeys[section];
lbl.font=[UIFont systemFontOfSize:30.0];
return lbl;
}
#pragma mark - 设置右边索引高度
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ return ;
} #pragma mark - 设置所有分区的标题的列表
-(NSArray<NSString *> *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
return self.arrkeys;
} #pragma mark - 单选控制格式
-(UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row==) {
return UITableViewCellAccessoryCheckmark;
}
else if(indexPath.row==){
return UITableViewCellAccessoryDetailDisclosureButton;
}
else if(indexPath.row==){
return UITableViewCellAccessoryDisclosureIndicator;
}else{
return UITableViewCellAccessoryNone;
}
} .........
@end

注:

通讯录中的各种属性和显示规格都在RootTableViewController.m里设置!!!

AppDelegate.h

#import <UIKit/UIKit.h>
#import "RootTableViewController.h"
@interface AppDelegate : UIResponder <UIApplicationDelegate> @property (strong, nonatomic) UIWindow *window; @end

AppDelegate.m

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window.rootViewController=[[UINavigationController alloc] initWithRootViewController:[[RootTableViewController alloc] initWithStyle:UITableViewStyleGrouped]]; return YES;
}
....... @end

iOS--通讯录(UITableViewController)的更多相关文章

  1. iOS 通讯录空格

    iOS 通讯录联系人出现 ASCII 码值为 160 的空格  NOTE:       这里的"空格"是指 在通讯录中取出的联系人中带有特殊空格 带有特殊空格的字符串 " ...

  2. iOS UITableViewCell UITableVIewController 纯代码开发

    iOS UITableViewCell UITableVIewController 纯代码开发 <原创> .纯代码 自定义UITableViewCell 直接上代码 ////// #imp ...

  3. Xamarin.Forms读取并展示Android和iOS通讯录 - TerminalMACS客户端

    Xamarin.Forms读取并展示Android和iOS通讯录 - TerminalMACS客户端 本文同步更新地址: https://dotnet9.com/11520.html https:// ...

  4. ios开发 UITableViewController

    iOS中显示数据列表最常用的一个控件,支持垂直滚动   UITableView的两种内置样式UITableViewStylePlain UITableViewStyleGrouped 数据源(data ...

  5. iOS 通讯录-获取联系人属性

    内容均来自关东升老师的ios开发指南 上一篇写了联系人框架的一些必须知道的知识 如今写一下读取联系人数据相关操作 要读取通讯录数据库 须要 创建通讯录对象 查询获取数据(全部或者部分) 获取通讯录某一 ...

  6. iOS通讯录相关知识-浅析

    本文来自于:贞娃儿的博客  http://blog.sina.com.cn/zhenwawaer  在开发一些应用中,我们如果需要iPhone设备中的通讯录信息.或者,需要开发通讯录相关的一些功能.那 ...

  7. IOS 通讯录 (访问,添加,修改)

      如何访问用户的通讯录 在iOS中,有2个框架可以访问用户的通讯录 AddressBookUI.framework 提供了联系人列表界面.联系人详情界面.添加联系人界面等 一般用于选择联系人 Add ...

  8. IOS通讯录的隐藏标签【电话】的特殊功能(在IOS11已失效)

    这功能比较适合有强迫症,爱折腾的人哈!! 规范了通讯录标签,以后可以轻松的知道别人是用短号还是亲情网给你打电话. 如果是长号还可以显示归属地. 也许从IOS8(不太清楚)开始自带了号码归属地显示功能, ...

  9. IOS Swift UITableViewcontroller实现点击空白处隐藏键盘

    在ios开发中,为了方便,我们经常使用UITableViewcontroller,比如搜索界面为了方便可能更多的使用UITableViewcontroller,那么问题就来了,当我点击搜索框的时候会弹 ...

  10. iOS 从UITableViewController中分离数据源

    之前看objc.io #1 Light View Controllers看到一个非常不错的技巧:从UITableViewController中分离数据源,这样能够减小UITableViewContro ...

随机推荐

  1. 【Android】Anroid5.0+新控件---酷炫标题栏的简单学习

    Android5.0+推出的新控件感觉特别酷,最近想模仿大神做个看图App出来,所以先把这些新控件用熟悉了. 新控件的介绍.使用等等网上相应的文章已经特别多了,题主也没那能力去写篇详解出来,本篇随笔记 ...

  2. 简单认识C#

    C#浅解众所周知c#是微软推出的一款完全没面向对象的编程语言,那么对象是什么?在现实生活中人们一提到对象首先想到的就是“情侣”!但是在我们的程序中对象是什么? 在程序中个能够区别于其他事物的独立个体我 ...

  3. Maven提高篇系列之(六)——编写自己的Plugin(本系列完)

    这是一个Maven提高篇的系列,包含有以下文章: Maven提高篇系列之(一)——多模块 vs 继承 Maven提高篇系列之(二)——配置Plugin到某个Phase(以Selenium集成测试为例) ...

  4. mongdo通用类(C#版)

    日前从公司离职,很快,还没休息就步入了现在的公司,开始跟着公司的脚步走. 公司的项目基本都是大数据的,所以在数据库上大部分都是使用Mongodb和Redis,基本都是Nosql型的数据库为主.以前自己 ...

  5. 关于ExtJs4的Grid带 查询 参数 分页(baseParams-->extraParams)

    (园里很多文章,美名其曰 :ExtJs GridPanel+查询条件+分页.  但是加查询条件后点击下一页,查询条件失效,求你们自己测试明白再显摆 不要误导我这种新人.) ExtJs6发布了,ExtJ ...

  6. MyEclipse10修改servlet模版

    Myeclipse10中servlet模版存放的位置与早些的版本不同,它存放在: MyEclipse\Common\plugins中的下面那个jar包中 com.genuitec.eclipse.wi ...

  7. idea配置maven并添加镜像配置

    1.打开maven存放文件夹找到 conf ->settings.xml 找到<mirrors>节点把下面内容写入节点内 配置为阿里云的镜像 <mirror> <i ...

  8. 2016 年沈阳网络赛---QSC and Master(区间DP)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5900 Problem Description Every school has some legend ...

  9. Lucene.net站内搜索—5、搜索引擎第一版实现

    目录 Lucene.net站内搜索—1.SEO优化 Lucene.net站内搜索—2.Lucene.Net简介和分词Lucene.net站内搜索—3.最简单搜索引擎代码Lucene.net站内搜索—4 ...

  10. java多线程之hashmap concurrenthashmap的状态同步

    最近在高并发的系统中发现,concurrenthashmap除了大家熟知的避免循环期间发生ConcurrentModificationException异常外,还有重要的一点是Retrievals r ...