通讯录
来源:互联网 发布:英语四级app排行榜mac 编辑:程序博客网 时间:2024/05/01 03:32
#import "ContactViewController.h"//通讯录: 最外面是字典, key(A,B,C...) - keyArray ; value(数组(image1,name1; image2, name2; ...), 可见每个元素都是字典)@interface ContactViewController ()<UITableViewDataSource>@property (nonatomic, copy)NSDictionary *contactDic;@property (nonatomic, copy)NSArray *keyArray;//装key 值的数组@endstatic NSString *identifier = @"abc";@implementation ContactViewController- (void)dealloc{ [_keyArray release]; [_contactDic release]; [super dealloc];}- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. UITableView *tabView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain]; [self.view addSubview:tabView]; tabView.dataSource = self; [tabView registerClass:[UITableViewCell class] forCellReuseIdentifier:identifier]; [tabView release]; NSString *path = [[NSBundle mainBundle] pathForResource:@"Contact" ofType:@"plist"]; self.contactDic = [NSDictionary dictionaryWithContentsOfFile:path]; //数组排序(A, B, C, D...) self.keyArray = [self.contactDic.allKeys sortedArrayUsingSelector:@selector(compare:)];}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}#pragma mark - UITableViewDataSource//多少分区- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return self.keyArray.count;}//多少行- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { NSString *key = self.keyArray[section]; NSArray *array = self.contactDic[key]; return array.count;}//单元格- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath]; NSString *key = self.keyArray[indexPath.section];//获取到 key 值 NSArray *array = self.contactDic[key];// 根据 key 值, 找到数组 //数组的 key, 数组的 value NSDictionary *dic = array[indexPath.row];//数组里面的具体某个元素 cell.imageView.image = [UIImage imageNamed:dic[@"image"]]; cell.textLabel.text = dic[@"name"]; return cell;}//分区数组- (nullable NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { return self.keyArray[section];}//右边的- (nullable NSArray<NSString *> *)sectionIndexTitlesForTableView:(UITableView *)tableView { return self.keyArray;}@end
0 0
- 通讯录
- 通讯录
- 通讯录
- 通讯录
- 通讯录
- 通讯录
- 通讯录
- 通讯录
- 通讯录
- 通讯录
- 通讯录
- 通讯录
- 通讯录
- 通讯录
- 通讯录
- 通讯录
- 通讯录
- 通讯录
- linux笔记
- 双拨速度不叠加
- python核心编程-找到每一个出现的部分
- 负载均衡调度算法大全
- 7进制字符串转为10进制的int类型数字(H3C笔试题)
- 通讯录
- Android 数据存数 II-数据备份简介和APP的安装路径
- 正常用的zabbix服务器进程,包括监控服务器本机
- 第二讲 完全背包问题 HD Piggy-Bank 1114
- Android SDK Manager 更新代理配置
- 勒布朗法则(LeBlanc)
- 使用MediaPlayer实现播放、暂停、继续和停止功能的简易音乐播放器
- 在Xcode中使用Git进行源码版本控制
- HDU 1065 I Think I Need a Houseboat【恶心的水题】