#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
#import "AppDelegate.h"
#import "ContactListViewController.h" // 导入联系人列表头文件
@interface AppDelegate ()
@end
@implementation AppDelegate
- (void)dealloc
{
[_window release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
ContactListViewController *contactVC = [[ContactListViewController alloc] initWithStyle:(UITableViewStylePlain)];
UINavigationController *naVC = [[UINavigationController alloc] initWithRootViewController:contactVC];
self.window.rootViewController = naVC;
[contactVC release];
[naVC release];
return YES;
}
@end
#import <UIKit/UIKit.h>
@interface ContactListViewController : UITableViewController
@end
#import "ContactListViewController.h"
#import "AddContactViewController.h"
#import "ContactDetailViewController.h"
#import "DataHandle.h"
#import "Contact.h"
#import "ContactCell.h"
@interface ContactListViewController ()
@property (nonatomic, retain)DataHandle *datahandle;
@property (nonatomic, retain) NSMutableDictionary *contactDic;
@property (nonatomic, retain) NSMutableArray *keysArray;
@end
@implementation ContactListViewController
- (void)dealloc
{
[_datahandle release];
[_contactDic release];
[_keysArray release];
[super dealloc];
}
- (void)viewWillAppear:(BOOL)animated {
_datahandle = [DataHandle shareDataHandle];
[super viewWillAppear:animated];
[self.tableView reloadData];
}
- (void)setData {
_datahandle = [DataHandle shareDataHandle];
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Class25ContactList" ofType:@"plist"];
NSDictionary *sourceDic = [NSDictionary dictionaryWithContentsOfFile:filePath];
for (NSString *key in sourceDic) {
NSArray *oneGroup = sourceDic[key];
NSMutableArray *modelArray = [NSMutableArray array];
for (NSDictionary *dic in oneGroup) {
Contact *contact = [[Contact alloc] init];
[contact setValuesForKeysWithDictionary:dic];
[modelArray addObject:contact];
[contact release];
}
[_datahandle.contactDic setObject:modelArray forKey:key];
}
_datahandle.keysArray = [[[_datahandle.contactDic allKeys] sortedArrayUsingSelector:@selector(compare:)] mutableCopy];
self.contactDic = _datahandle.contactDic;
self.keysArray = _datahandle.keysArray;
}
- (void)viewDidLoad {
[self setData];
[super viewDidLoad];
self.title = @"通讯录";
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:(UIBarButtonSystemItemAdd) target:self action:@selector(addNewContact:)];
self.navigationItem.rightBarButtonItem = self.editButtonItem;
self.navigationItem.rightBarButtonItem.title = @"编辑";
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
#pragma mark- 自定义方法
- (NSUInteger)numberOfSection {
return [_datahandle.keysArray count];
}
- (NSUInteger)numberOfRowsInSection:(NSInteger)section {
return [_datahandle.contactDic[_datahandle.keysArray[section]] count];
}
- (Contact *)contactOfIndexPath:(NSIndexPath *)indexPath {
return _datahandle.contactDic[_datahandle.keysArray[indexPath.section]][indexPath.row];
}
#pragma mark- Table view data source
#pragma mark- 分区数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Potentially incomplete method implementation.
return [self numberOfSection];
}
#pragma mark- 各个分区行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete method implementation.
return [self numberOfRowsInSection:section];
}
#pragma mark- 加载单元格
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *reuseIdentifier = @"cell";
ContactCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
if (cell == nil) {
cell = [[ContactCell alloc] initWithStyle:(UITableViewCellStyleSubtitle) reuseIdentifier:reuseIdentifier];
}
Contact *contact = [self contactOfIndexPath:indexPath];
[cell setContact:contact];
return cell;
}
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
return _datahandle.keysArray;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return _datahandle.keysArray[section];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 120;
}
#pragma mark- 当选中单元格执行
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
ContactDetailViewController *detailVC = [[ContactDetailViewController alloc] init];
detailVC.contact = [self contactOfIndexPath:indexPath];
detailVC.indexPath = indexPath;
[self.navigationController pushViewController:detailVC animated:YES];
[detailVC release];
}
#pragma mark- 添加联系人
- (void)addNewContact:(UIBarButtonItem *)barButton {
AddContactViewController *addContactVC = [[AddContactViewController alloc] init];
UINavigationController *naVC =[[UINavigationController alloc] initWithRootViewController:addContactVC];
[self presentViewController:naVC animated:YES completion:nil];
[addContactVC release];
[naVC release];
}
#pragma mark- 编辑触发的方法
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing:editing animated:animated];
[(UITableView *)self.view setEditing:editing animated:animated];
if (editing == YES) {
self.navigationItem.rightBarButtonItem.title = @"完成";
} else {
self.navigationItem.rightBarButtonItem.title = @"编辑";
}
}
#pragma mark- 指定被编辑行
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
#pragma mark- 提交编辑
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
if ([_datahandle.contactDic[_datahandle.keysArray[indexPath.section]] count] == 1) {
[_datahandle.contactDic removeObjectForKey:_datahandle.keysArray[indexPath.section]];
[_datahandle.keysArray removeObjectAtIndex:indexPath.section];
[tableView deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:(UITableViewRowAnimationLeft)];
} else {
[_datahandle.contactDic[_datahandle.keysArray[indexPath.section]] removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
}
}
#pragma mark- 完成移动
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
NSDictionary *contact = _datahandle.contactDic[_datahandle.keysArray[fromIndexPath.section]][fromIndexPath.row];
[_datahandle.contactDic[_datahandle.keysArray[fromIndexPath.section]] removeObjectAtIndex:fromIndexPath.row];
[_datahandle.contactDic[_datahandle.keysArray[toIndexPath.section]] insertObject:contact atIndex:toIndexPath.row];
}
#pragma mark- 限制跨区移动
- (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath {
if (sourceIndexPath.section == proposedDestinationIndexPath.section) {
return proposedDestinationIndexPath;
} else {
return sourceIndexPath;
}
}
#pragma mark- 指定是否可移动
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
@end
#import <UIKit/UIKit.h>
@class Contact;
@interface ContactDetailViewController : UIViewController
@property (nonatomic, retain) NSIndexPath *indexPath;
@property (nonatomic, retain) Contact *contact;
@end
#import "ContactDetailViewController.h"
#import "Contact.h" //导入model
#import "ContactDetailView.h" //导入联系人详情视图
#import "DataHandle.h"
@interface ContactDetailViewController ()<UINavigationControllerDelegate, UIImagePickerControllerDelegate>
@property (nonatomic, retain)DataHandle *datahandle;
@property (nonatomic, retain)ContactDetailView *detailView;
@property (nonatomic, retain)UIButton *changeButton;
@property (nonatomic, retain)UIImage *image;
@end
@implementation ContactDetailViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
self.navigationController.navigationBar.translucent = NO;
self.title = _contact.name;
_detailView = [[ContactDetailView alloc] initWithFrame:[UIScreen mainScreen].bounds];
_detailView.contact = _contact;
[_detailView setContactDetailViewEditing:NO];
_changeButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
_changeButton.frame = CGRectMake(150, 340, 75, 30);
[_changeButton setTitle:@"提交" forState:(UIControlStateNormal)];
[_changeButton addTarget:self action:@selector(changeAction:) forControlEvents:(UIControlEventTouchUpInside)];
[_detailView addSubview:_changeButton];
_changeButton.hidden = YES;
[self.view addSubview:_detailView];
[_detailView release];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"更改" style:(UIBarButtonItemStylePlain) target:self action:@selector(changeContactInfo:)];
}
- (void)changeContactInfo:(UIBarButtonItem *)rihgtButton{
[_detailView setContactDetailViewEditing:YES];
[_detailView.nameLT becomeFirstResponder];
_changeButton.hidden = NO;
_detailView.iconImageView.userInteractionEnabled = YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pickImage:)];
[_detailView.iconImageView addGestureRecognizer:tap];
[tap release];
}
- (void)changeAction:(UIButton *)button {
_datahandle = [DataHandle shareDataHandle];
NSMutableString *name = [_detailView.nameLT.text mutableCopy];
CFStringTransform((CFMutableStringRef)name, NULL, kCFStringTransformToLatin, false);
CFStringTransform((__bridge CFMutableStringRef)name, 0, kCFStringTransformStripDiacritics, NO);
NSString *groupName = [[name substringToIndex:1] uppercaseString];
BOOL groupIsExisted = NO;
_contact.name = _detailView.nameLT.text;
_contact.age = _detailView.ageLT.text;
_contact.gender = _detailView.genderLT.text;
_contact.phoneNumber = _detailView.phoneNumberLT.text;
_contact.hobby = _detailView.hobbyTV.text;
_contact.icon = [NSString stringWithFormat:@"%@.jpg", _contact.name];
if (_image != nil) {
_contact.iconImage = _image;
} else {
_contact.iconImage = _contact.iconImage;
}
for (NSString *str in _datahandle.keysArray) {
if ([name isEqualToString:str]) {
groupIsExisted = YES;
}
}
if ([_datahandle.keysArray[_indexPath.section] isEqualToString:groupName]) {
[_datahandle.contactDic[_datahandle.keysArray[_indexPath.section]] replaceObjectAtIndex:_indexPath.row withObject:_contact];
} else {
if (groupIsExisted == YES) {
if ([_datahandle.contactDic[_datahandle.keysArray[_indexPath.section]] count] == 1) {
[_datahandle.contactDic removeObjectForKey:_datahandle.keysArray[_indexPath.section]];
[_datahandle.keysArray removeObjectAtIndex:_indexPath.section];
NSLog(@"%@",_datahandle.contactDic[groupName] );
[_datahandle.contactDic[groupName] addObject:_contact];
NSLog(@"%@",_datahandle.contactDic[groupName] );
} else {
[_datahandle.contactDic[_datahandle.keysArray[_indexPath.section]] removeObjectAtIndex:_indexPath.row];
[_datahandle.contactDic[groupName] addObject:_contact];
}
} else {
NSMutableArray *arr = [NSMutableArray array];
if ([_datahandle.contactDic[_datahandle.keysArray[_indexPath.section]] count] == 1) {
[_datahandle.contactDic removeObjectForKey:_datahandle.keysArray[_indexPath.section]];
[_datahandle.keysArray removeObjectAtIndex:_indexPath.section];
} else {
[_datahandle.contactDic[_datahandle.keysArray[_indexPath.section]] removeObjectAtIndex:_indexPath.row];
}
[arr addObject:_contact];
[_datahandle.contactDic setObject:arr forKey:groupName];
_datahandle.keysArray = [[[_datahandle.contactDic allKeys] sortedArrayUsingSelector:@selector(compare:)] mutableCopy];
}
}
[_detailView setContactDetailViewEditing:NO];
_changeButton.hidden = YES;
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
_detailView.iconImageView.image = image;
_image = [image retain];
[picker dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark- 处理tap事件
- (void)pickImage:(UITapGestureRecognizer *)tap {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
[picker setSourceType:(UIImagePickerControllerSourceTypePhotoLibrary)];
picker.delegate = self;
[self presentViewController:picker animated:YES completion:nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
#import <UIKit/UIKit.h>
@interface AddContactViewController : UIViewController
@end
#import "AddContactViewController.h"
#import "ContactDetailView.h"
#import "DataHandle.h"
#import "Contact.h"
@interface AddContactViewController ()<UINavigationControllerDelegate, UIImagePickerControllerDelegate>
@property (nonatomic, retain) ContactDetailView *addView;
@property (nonatomic, retain)DataHandle *datahandle;
@property (nonatomic, retain)UIImage *image;
@end
@implementation AddContactViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"添加联系人";
self.view.backgroundColor = [UIColor whiteColor];
self.navigationController.navigationBar.translucent = NO;
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:(UIBarButtonItemStylePlain) target:self action:@selector(gotoContactList:)];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"确认" style:(UIBarButtonItemStylePlain) target:self action:@selector(addContact:)];
_addView = [[ContactDetailView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[_addView setContactDetailViewEditing:YES];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pickImage:)];
[_addView.iconImageView addGestureRecognizer:tap];
[tap release];
_addView.iconImageView.userInteractionEnabled = YES;
[self.view addSubview:_addView];
[_addView release];
_datahandle = [DataHandle shareDataHandle];
}
#pragma mark- 返回联系人列表
- (void)gotoContactList:(UIBarButtonItem *)leftButton {
[self dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark- 添加联系人
- (void)addContact:(UIBarButtonItem *)rightButton {
if ([_addView.nameLT.text length] == 0 || [_addView.phoneNumberLT.text length] == 0) {
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"提示" message:@"添加不成功" delegate:self cancelButtonTitle:@"确认" otherButtonTitles:@"取消", nil];
[message show];
} else {
NSMutableString *name = [_addView.nameLT.text mutableCopy];
CFStringTransform((CFMutableStringRef)name, NULL, kCFStringTransformToLatin, false);
CFStringTransform((__bridge CFMutableStringRef)name, 0, kCFStringTransformStripDiacritics, NO);
NSDictionary *contactDic = @{@"name" : _addView.nameLT.text, @"gender" : _addView.genderLT.text, @"phoneNumber" : _addView.phoneNumberLT.text, @"hobby" : _addView.hobbyTV.text, @"picture" : @""};
NSString *groupName = [[name substringToIndex:1] uppercaseString];
Contact *contact = [[Contact alloc] init];
[contact setValuesForKeysWithDictionary:contactDic];
contact.iconImage = _image;
NSMutableArray *group = [_datahandle.contactDic objectForKey:groupName];
if (group) {
[group addObject:contact];
} else {
group = [NSMutableArray array];
[group addObject:contact];
[_datahandle.contactDic setValue:group forKey:groupName];
_datahandle.keysArray = [[[_datahandle.contactDic allKeys] sortedArrayUsingSelector:@selector(compare:)] mutableCopy];
}
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"提示" message:@"添加成功" delegate:self cancelButtonTitle:@"确认" otherButtonTitles:@"取消", nil];
[message show];
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
_addView.iconImageView.image = image;
_image = [image retain];
[picker dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark- 处理tap事件
- (void)pickImage:(UITapGestureRecognizer *)tap {
NSLog(@"2222");
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
[picker setSourceType:(UIImagePickerControllerSourceTypePhotoLibrary)];
picker.delegate = self;
[self presentViewController:picker animated:YES completion:nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
#import <Foundation/Foundation.h>
@interface DataHandle : NSObject
@property (nonatomic, retain) NSMutableDictionary *contactDic;
@property (nonatomic, retain) NSMutableArray *keysArray;
+ (DataHandle *)shareDataHandle;
@end
#import "DataHandle.h"
@implementation DataHandle
- (void)dealloc
{
[_contactDic release];
[_keysArray release];
[super dealloc];
}
static DataHandle *handle = nil;
+ (DataHandle *)shareDataHandle {
@synchronized(self) {
if (handle == nil) {
handle = [[DataHandle alloc] init];
}
return handle;
}
}
- (instancetype)init
{
self = [super init];
if (self) {
self.contactDic = [NSMutableDictionary dictionary];
self.keysArray = [NSMutableArray array];
}
return self;
}
@end
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface Contact : NSObject
@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) NSString *gender;
@property (nonatomic, copy) NSString *age;
@property (nonatomic, copy) NSString *phoneNumber;
@property (nonatomic, copy) NSString *hobby;
@property (nonatomic, copy) NSString *icon;
@property (nonatomic, retain) UIImage *iconImage;
@end
#import "Contact.h"
@implementation Contact
- (void)dealloc
{
[_name release];
[_gender release];
[_age release];
[_phoneNumber release];
[_hobby release];
[_icon release];
[_iconImage release];
[super dealloc];
}
- (void)setValue:(id)value forKey:(NSString *)key {
[super setValue:value forKey:key];
}
- (void)setValue:(id)value forUndefinedKey:(NSString *)key {
if ([key isEqual:@"picture"]) {
self.icon = value;
self.iconImage = [UIImage imageNamed:value];
}
}
@end
#import <UIKit/UIKit.h>
@class Contact;
@interface ContactDetailView : UIView
@property (nonatomic, retain, readonly) UIImageView *iconImageView;
@property (nonatomic, retain, readonly) UITextField *nameLT;
@property (nonatomic, retain, readonly) UITextField *genderLT;
@property (nonatomic, retain, readonly) UITextField *ageLT;
@property (nonatomic, retain, readonly) UITextField *phoneNumberLT;
@property (nonatomic, retain, readonly) UITextView *hobbyTV;
@property (nonatomic, retain) Contact *contact;
- (void)setContactDetailViewEditing:(BOOL)edit;
@end
#import "ContactDetailView.h"
#import "Contact.h"
@implementation ContactDetailView
- (void)dealloc
{
[_iconImageView release];
[_nameLT release];
[_genderLT release];
[_ageLT release];
[_phoneNumberLT release];
[_hobbyTV release];
[_contact release];
[super dealloc];
}
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
_iconImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 20, 120, 180)];
_iconImageView.backgroundColor = [UIColor grayColor];
[self addSubview:_iconImageView];
_nameLT = [[UITextField alloc] initWithFrame:CGRectMake(140, 20, 200, 30)];
[self addSubview:_nameLT];
_genderLT = [[UITextField alloc] initWithFrame:CGRectMake(140, 60, 95, 30)];
[self addSubview:_genderLT];
_ageLT = [[UITextField alloc] initWithFrame:CGRectMake(245, 60, 95, 30)];
[self addSubview:_ageLT];
_phoneNumberLT = [[UITextField alloc] initWithFrame:CGRectMake(140, 100, 200, 30)];
[self addSubview:_phoneNumberLT];
_hobbyTV = [[UITextView alloc] initWithFrame:CGRectMake(10, 210, 335, 100)];
_hobbyTV.backgroundColor = [UIColor cyanColor];
[self addSubview:_hobbyTV];
}
return self;
}
- (void)setContactDetailViewEditing:(BOOL)edit {
if(edit == YES) {
[self contactDetailViewStateEditing];
} else {
[self contactDetailViewStateShowing];
}
}
- (void)contactDetailViewStateShowing {
_iconImageView.userInteractionEnabled = NO;
_nameLT.enabled = NO;
_genderLT.enabled = NO;
_ageLT.enabled = NO;
_phoneNumberLT.enabled = NO;
_hobbyTV.editable = NO;
_nameLT.borderStyle = UITextBorderStyleLine;
_genderLT.borderStyle = UITextBorderStyleLine;
_ageLT.borderStyle = UITextBorderStyleLine;
_phoneNumberLT.borderStyle = UITextBorderStyleLine;
}
- (void)contactDetailViewStateEditing {
_iconImageView.userInteractionEnabled = YES;
_nameLT.enabled = YES;
_genderLT.enabled = YES;
_ageLT.enabled = YES;
_phoneNumberLT.enabled = YES;
_hobbyTV.editable = YES;
_nameLT.borderStyle = UITextBorderStyleRoundedRect;
_genderLT.borderStyle = UITextBorderStyleRoundedRect;
_ageLT.borderStyle = UITextBorderStyleRoundedRect;
_phoneNumberLT.borderStyle = UITextBorderStyleRoundedRect;
_nameLT.placeholder = @"姓名";
_genderLT.placeholder = @"性别";
_ageLT.placeholder = @"年龄";
_phoneNumberLT.placeholder = @"联系方式";
}
- (void)setContact:(Contact *)contact {
if (_contact != contact) {
[_contact release];
_contact = [contact retain];
}
_iconImageView.image = _contact.iconImage;
_nameLT.text = _contact.name;
_ageLT.text = _contact.age;
_genderLT.text = _contact.gender;
_phoneNumberLT.text = _contact.phoneNumber;
_hobbyTV.text = _contact.hobby;
}
@end
#import <UIKit/UIKit.h>
@class Contact;
@interface ContactCell : UITableViewCell
@property (nonatomic, retain, readonly) UIImageView *iconImage;
@property (nonatomic, retain, readonly) UILabel *nameLable;
@property (nonatomic, retain, readonly) UILabel *phoneNumber;
@property (nonatomic, retain) Contact *contact;
@end
#import "ContactCell.h"
#import "Contact.h"
@implementation ContactCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
_iconImage = [[UIImageView alloc] initWithFrame:CGRectMake(3, 5, 90, 110)];
[self.contentView addSubview:_iconImage];
_nameLable = [[UILabel alloc] initWithFrame:CGRectMake(105, 5, 120, 30)];
[self.contentView addSubview:_nameLable];
_phoneNumber = [[UILabel alloc] initWithFrame:CGRectMake(105, 50, 160, 30)];
[self.contentView addSubview:_phoneNumber];
}
return self;
}
- (void)setContact:(Contact *)contact {
if (_contact != contact) {
[_contact release];
_contact = [contact retain];
}
_iconImage.image = contact.iconImage;
_nameLable.text = contact.name;
_phoneNumber.text = contact.phoneNumber;
}
- (void)awakeFromNib {
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
}
@end