#import "ContactListTableViewController.h"

#import "Contact.h"

#import "ContactCell.h"

#import "GirlCell.h"

@interface ContactListTableViewController ()

@property (nonatomic,retain)NSMutableArray *allKeys;

@property (nonatomic,retain)NSMutableDictionary *groupDic;

@end

@implementation ContactListTableViewController

- (void)dealloc

{

self.allKeys = nil;

self.groupDic = nil;

[super dealloc];

}

- (id)initWithStyle:(UITableViewStyle)style

{

self = [super initWithStyle:style];

if (self) {

// Custom initialization

}

return self;

}

- (void)viewDidLoad

{

[super viewDidLoad];

// Uncomment the following line to preserve selection between presentations.

// self.clearsSelectionOnViewWillAppear = NO;

// Uncomment the following line to display an Edit button in the navigation bar for this view controller.

//     self.navigationItem.rightBarButtonItem = self.editButtonItem;

//读取数据

[self reloadData];

//自定义navigationBar

self.navigationItem.title = @"联系人";

self.view.backgroundColor = [UIColor brownColor];

}

//读取数据

- (void)reloadData

{

//获取文件路径

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Contact.plist" ofType:nil];

//通过文件路径获取数据

self.groupDic = [NSMutableDictionary dictionaryWithContentsOfFile:filePath];

//获取所有的key

NSArray *keys = [_groupDic allKeys];

//转换为可变数组并排序

self.allKeys = [NSMutableArray arrayWithArray:keys];

[_allKeys sortUsingSelector:@selector(compare:)];

//封装对象

//遍历

for (NSString *key in _allKeys) {

NSMutableArray *group = [_groupDic valueForKey:key];

//创建对象数组

NSMutableArray *newGroup = [[NSMutableArray alloc] init];

//遍历数组

for (NSMutableDictionary *perDic in group) {

//创建对象

Contact *contact = [[Contact alloc] init];

//赋值

[contact setValuesForKeysWithDictionary:perDic];

//放入数组

[newGroup addObject:contact];

}

//替换数组

[_groupDic setValue:newGroup forKey:key];

}

}

//获取对应分组

- (NSMutableArray *)getGroupWithSection:(NSInteger)section

{

NSString *key = [_allKeys objectAtIndex:section];

NSMutableArray *group = [_groupDic valueForKey:key];

return group;

}

- (void)didReceiveMemoryWarning

{

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

// Return the number of sections.

return _allKeys.count;

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

NSMutableArray *group = [self getGroupWithSection:section];

// Return the number of rows in the section.

return group.count;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

static NSString *identifier = @"aa";

static NSString *girl = @"girl";

//获取对应分组

NSMutableArray *group = [self getGroupWithSection:indexPath.section];

//获取对应联系人

Contact *contact = [group objectAtIndex:indexPath.row];

if ([contact.sex isEqualToString:@"男"]) {

ContactCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];

if (!cell) {

cell = [[ContactCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];

}

cell.contact = contact;

return cell;

}

GirlCell *cell = [tableView dequeueReusableCellWithIdentifier:girl];

if (!cell) {

cell = [[GirlCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:girl];

}

cell.contact = contact;

//    ContactCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];

//    if (!cell) {

//        cell = [[ContactCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];

//    }

//

//    //先获取对应分组

//    NSMutableArray *group = [self getGroupWithSection:indexPath.section];

//    //获取对应联系人

//    Contact *contact = [group objectAtIndex:indexPath.row];

//    cell.contact = contact;

//

////    //cell赋值

////    cell.textLabel.text = contact.name;

////    cell.detailTextLabel.text = contact.phoneNumber;

////    cell.imageView.image = [UIImage imageNamed:contact.photoName];

//

//    // Configure the cell...

//

////    cell.nameView.text = contact.name;

////    cell.photoView.image = [UIImage imageNamed:contact.photoName];

////    cell.phoneView.text = contact.phoneNumber;

////    cell.descriptionView.text = contact.description;

return cell;

}

//分区title

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

{

return [_allKeys objectAtIndex:section];

}

//侧边导航栏

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView

{

return _allKeys;

}

//row高度

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

//获取对应分组

NSMutableArray *group = [self getGroupWithSection:indexPath.section];

//获取对应的联系人

Contact *contact = [group objectAtIndex:indexPath.row];

//获取高度

CGFloat height = [GirlCell heightWithString:contact.description];

return 120 + height;

}

UITableViewCell的更多相关文章

  1. UITableViewCell定制

    UITableViewCell定制 效果       特点 1.可以添加不同的TableViewCell,可以定制不同的cell样式; 2.可以动态改变cell的高度; 3.可以随意摆放你cell的位 ...

  2. 自定义UITableViewCell实现左滑动多菜单功能LeftSwipe

    今天愚人节,小伙们,愚人节快乐! 实现一个小功能,滑动菜单,显示隐藏的功能菜单, 先上图:                       这里尝试用了下使用三个方式来实现了这个功能: 1.使用自定义UI ...

  3. 【ios开发】UITableViewCell的重用

    移动开发需要解决的一个问题就是资源稀缺的问题.多数情况下是内存问题. 虽然现在的手机都号称大内存,高配置.但是移动app所占用的资源也在跟着不断膨胀, 也是造成内存不足的主要原因. 在前面的例子中,还 ...

  4. UITableViewCell 的附件类型 accessoryType 选中、详情、箭头

    UITableViewCell * cell = [[UITableViewCell alloc] init]; 设置cell的附件类型: // >1 打钩 选中//    cell.acces ...

  5. 【转】自定义UITableViewCell(registerNib: 与 registerClass: 的区别)

    自定义UITableViewCell大致有两类方法: 使用nib 1.xib中指定cell的Class为自定义cell类型(注意不是设置File's Owner的class) 2.调用 tableVi ...

  6. 动态计算UITableViewCell高度

    动态计算UITableViewCell高度 UILabel in UITableViewCell Auto Layout - UILabel的属性Lines设为了0表示显示多行.Auto Layout ...

  7. 【Swift】UITableViewCell 中 TTTAttributedLabel 超链接无法点击的问题

    前言 还以为是自己代码写的有问题,用法和别的地方都一样,但是这个是在 UITableViewCell 中使用,另外在 tableHeaderView 中使用也没用这个问题 —— 使用 TTTAttri ...

  8. 【swift学习笔记】三.使用xib自定义UITableViewCell

    使用xib自定义tableviewCell看一下效果图 1.自定义列 新建一个xib文件 carTblCell,拖放一个UITableViewCell,再拖放一个图片和一个文本框到tableviewc ...

  9. UITableViewCell的重用机制

    UITabelView一般会显示大量数据,如果有多少条数据就新建多少个cell,那么对于内存来说是种极大的负担,这样自然是不合理的,所以才会有重用机制 比如一个家庭办酒席,一共有13桌,每桌20个菜, ...

  10. iOS UITableViewCell的"滑动出现多个按钮"

    本文授权转载,作者:@夏天是个大人了 前言: 本篇博客其实就是想介绍tableviewcell滑动的一些"事",昨天在逛github的时候看到的还挺有意思的三方库,简单用了一下感觉 ...

随机推荐

  1. final finally finalize

    final  //如果不是final 的话,我可以在checkInt方法内部把i的值改变(有意或无意的,       //虽然不会改变实际调用处的值),特别是无意的,可能会引用一些难以发现的BUG   ...

  2. caffe + ubuntu16.04 (version without GPU)

    This Guide is based on caffe github wiki guide (https://github.com/BVLC/caffe/wiki/Ubuntu-16.04-or-1 ...

  3. 在Ubuntu下使用 csapp.h 和 csapp.c

    它山之石可以攻玉. 对于<深入理解计算机系统>这本神人写就的神书, 我等凡人就不评论什么啦. 这本书的 第二,三 部分, 真的真的对我理解操作系统有很大的帮助. (当然, 如果你不看第一部 ...

  4. 【java基础】面向对象的三大特征---多态

    java的引用变量有两种类型,编译时类型和运行时类型,如果编译时类型和运行时类型不一致,就会出现多态. 多态分为: 运行时多态 java运行时系统根据调用该方法的实例的类型来决定选择调用哪个方法则被称 ...

  5. JS刷新父窗口的几种方式<转>

    常用的有:   window.opener.location.reload();    和  window.location.reload(); 浮层内嵌iframe及frame集合窗口,刷新父页面的 ...

  6. svn 版本控制

    首先来下载和搭建SVN服务器. Subversion已经迁移到apache网站上了,下载地址: http://subversion.apache.org/packages.html windows操作 ...

  7. 深入理解javascript系列,读书笔记

    深入理解JavaScript系列(2):揭秘命名函数表达式 1.讲了函数声明和函数表达式的区别,包括一些在函数提升上的区别 2.如果给函数表达式的函数也取名,会在调试的时候受益 3.不要在block( ...

  8. JSON API免费接口

    来自:http://www.bejson.com/knownjson/webInterface/ 电商接口 京东获取单个商品价格接口: http://p.3.cn/prices/mgets?skuId ...

  9. centos 6.5重置Root密码

    按任意键进入菜单界面 在开始引导的时候,进入开机启动界面(如下图) 然后按一下键盘上面的"e" 3.进入如下图界面,我这边选择第二个按下键盘上的"e"键.(不同 ...

  10. 0525 Scrum 项目 7.0

    Sprint回顾 让我们一次比一次做得更好.   1.回顾组织 主题:“我们怎样才能在下个sprint中做的更好?” 时间:设定为1至2个小时. 参与者:整个团队. 场所:能够在不受干扰的情况下讨论. ...