UI0810通讯录加强版

来源:互联网 发布:淘宝导航代码大全 编辑:程序博客网 时间:2024/05/01 06:01
////  AppDelegate.m//  UI0810通讯录加强版////  Created by dllo on 15/8/10.//  Copyright (c) 2015年 Clare. All rights reserved.//#import "AppDelegate.h"#import "MainViewController.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]];    // Override point for customization after application launch.    self.window.backgroundColor = [UIColor whiteColor];    [self.window makeKeyAndVisible];    [_window release];        MainViewController *mainVC = [[MainViewController alloc] init];    UINavigationController *naVC = [[UINavigationController alloc] initWithRootViewController:mainVC];    self.window.rootViewController = naVC;    [naVC release];    [mainVC release];            return YES;}
////  MainViewController.m//  UI0810通讯录加强版////  Created by dllo on 15/8/10.//  Copyright (c) 2015年 Clare. All rights reserved.//#import "MainViewController.h"#import "Student.h"#import "ManCell.h"#import "WomanCell.h"#import "AddViewController.h"#import "ChangeViewController.h"#define WIDTH self.view.frame.size.width#define HEIGHT self.view.frame.size.height// 接口部分,描述类的特征和行为@interface MainViewController ()<UITableViewDataSource,UITableViewDelegate,AddViewController,ChangeViewController>@property(nonatomic, retain)UITableView *tableView;@property(nonatomic, retain)NSMutableArray *arr;@property(nonatomic, retain)NSMutableArray *picArr;@property(nonatomic, retain)Student *stu;@end// 实现部分,类的实现方法@implementation MainViewController- (void)dealloc{    [_tableView release];    [_arr release];    [_picArr release];    [_stu release];    [super dealloc];    }// 自定义初始化- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{    // 初始化方法    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];    if (self) {        [self createData];    }    // 初始化自身变量    return self;}// 初始化方法的实现,创建数据- (void)createData{    // 获取数据源plist中的数据    NSString *path = [[NSBundle mainBundle] pathForResource:@"Student" ofType:@"plist"];    //定义一个不可变数组,将获取到的plist中的数据赋值给他    NSArray *arr = [NSArray arrayWithContentsOfFile:path];        // 定义一个新的可变数组,用来装载符合条件的数据    self.arr = [NSMutableArray array];        // 定义一个整形变量i用来进行图片的切换    NSInteger i = 1;        // 定义一个可变字典使用for-in的方法对数组arr进行遍历    for (NSMutableDictionary *dic in arr) {                // 定义一个model型的stu对象        self.stu = [[Student alloc] init];                // 通过KVC的方法从字典中将信息映射到对象stu中        [self.stu setValuesForKeysWithDictionary:dic];                // 在对象stu中再加入一条图片名属性        self.stu.imageName = [NSString stringWithFormat:@"%ld.jpg", i];        i++;                // 用定义的新的可变数组接收stu对象        [self.arr addObject:self.stu];        // 对试图对象进行释放        [self.stu release];    }}- (void)viewDidLoad {    [super viewDidLoad];    // Do any additional setup after loading the view.        // 定义导航的名字为通讯录    self.title = @"通讯录";    // 设置试图view的背景颜色    self.view.backgroundColor = [UIColor grayColor];    // 设置导航条不透明    self.navigationController.navigationBar.translucent = NO;        // 在导航条中设置一个右上角按钮用来跳转到添加页面    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"1.png"] style:UIBarButtonItemStylePlain target:self action:@selector(rightAction:)]autorelease];        // 定义一个属性tableview    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT - 64)style:UITableViewStylePlain];        // tableview签订协议    self.tableView.delegate = self;    self.tableView.dataSource = self;        // 将tableview加载到view上    [self.view addSubview:self.tableView];        // 对tableview进行释放    [_tableView release];        // 设置tableview的每一行高度    self.tableView.rowHeight = 250;        // 去掉tableview中的分割线    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;    }- (void)rightAction:(UIButton *)button{    AddViewController *addVC = [[AddViewController alloc] init];    // 5.设置代理人    addVC.delegate = self;    // 点击导航右上角按钮推出添加界面    [self.navigationController pushViewController:addVC animated:YES];    [addVC release];}// 6.实现协议方法,接收从添加页面传过来的值,并分别赋值- (void)addName:(NSString *)name Sex:(NSString *)sex Hobby:(NSString *)hobby Phone:(NSString *)phone ImageName:(NSString *)imageName{    // 将穿过来的值赋值到model中的stu里    self.stu.name = name;    self.stu.sex = sex;    self.stu.hobby = hobby;    self.stu.phone = phone;    self.stu.imageName = imageName;        // 接收完值后刷新    [self.tableView reloadData];}// tableview必须执行的第一个方法,确定有多少行- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{    // 返回的是数组中元素的个数,每一个元素占一行    return self.arr.count;}// tableview必须执行的第二个方法- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{    // 如果数组中的sex参数为男执行此处//    self.stu = self.arr[indexPath.row];//    if ([self.stu.sex isEqualToString:@"男"]) {    if ([[self.arr[indexPath.row] sex] isEqualToString:@"男"]) {        static NSString *reuse = @"manReuse";        ManCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];        if (!cell) {            cell = [[[ManCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse] autorelease];        }        // 通过getter的方法获得对应的数据        cell.nameLabel.text = [self.arr[indexPath.row] name];        cell.sexLabel.text = [self.arr[indexPath.row] sex];        cell.hobbyLabel.text = [self.arr[indexPath.row] hobby];        cell.phoneLabel.text = [self.arr[indexPath.row] phone];        cell.leftImage.image = [UIImage imageNamed:[self.arr[indexPath.row] imageName]];        return cell;    } else {        static NSString *reuse = @"womanReuse";        WomanCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];        if (!cell) {            cell= [[[WomanCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse] autorelease];        }        cell.name.text = [self.arr[indexPath.row] name];        cell.sex.text = [self.arr[indexPath.row] sex];        cell.hobby.text = [self.arr[indexPath.row] hobby];        cell.phone.text = [self.arr[indexPath.row] phone];        cell.rightImage.image = [UIImage imageNamed:[self.arr[indexPath.row] imageName]];        return cell;    }    }- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{    ChangeViewController *changeVC = [[ChangeViewController alloc] init];    [self.navigationController pushViewController:changeVC animated:YES];    // 从前往后传值,将对应的数组,下标等传到修改页面    changeVC.self.arrC = self.arr;    changeVC.row = indexPath.row;    changeVC.deleagte = self;    [changeVC release];}// 修改页面从后往前传值,调用的方法- (void)changeStudent:(Student *)stu row:(NSInteger)row{    // 用属性的arr来接收对应传过来的下标和数据    [self.arr replaceObjectAtIndex:row withObject:stu];    // 刷新tableview    [self.tableView reloadData];}- (void)didReceiveMemoryWarning {    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}/* #pragma mark - Navigation  // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */@end

////  AddViewController.h//  UI0810通讯录加强版////  Created by dllo on 15/8/11.//  Copyright (c) 2015年 Clare. All rights reserved.//#import <UIKit/UIKit.h>// 1. 声明一份协议@protocol AddViewController <NSObject>- (void)addName:(NSString *)name            Sex:(NSString *)sex          Hobby:(NSString *)hobby          Phone:(NSString *)phone      ImageName:(NSString *)imageName;@end@interface AddViewController : UIViewController// 2.设置代理人属性@property(nonatomic, assign)id<AddViewController>delegate;@end

////  AddViewController.m//  UI0810通讯录加强版////  Created by dllo on 15/8/11.//  Copyright (c) 2015年 Clare. All rights reserved.//#import "AddViewController.h"#import "Student.h"#define HEIGHT self.view.frame.size.height@interface AddViewController ()<UITextFieldDelegate>@property(nonatomic, retain)UITextField *nameTF;@property(nonatomic, retain)UITextField *sexTF;@property(nonatomic, retain)UITextField *hobbyTF;@property(nonatomic, retain)UITextField *phoneTF;@property(nonatomic, retain)UIImageView *image;@end@implementation AddViewController- (void)dealloc{    [_nameTF release];    [_sexTF release];    [_hobbyTF release];    [_phoneTF release];    [_image release];    [super dealloc];}- (void)viewDidLoad {    [super viewDidLoad];    // Do any additional setup after loading the view.    self.view.backgroundColor = [UIColor whiteColor];    UIScrollView *imageScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(100, 50, 200, 200)];    imageScrollView.backgroundColor = [UIColor lightGrayColor];    [self.view addSubview:imageScrollView];    [imageScrollView release];    imageScrollView.tag = 1000;    imageScrollView.contentSize = CGSizeMake(200 * 22, 200);    imageScrollView.pagingEnabled = YES;    for (NSInteger i = 1; i < 23; i++) {        NSString *picName = [NSString stringWithFormat:@"%ld.jpg", i];        UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:picName]];        imageView.frame = CGRectMake(200 * (i - 1), 0, 200, 200);        [imageScrollView addSubview:imageView];        [imageView release];    }        UILabel *name = [[UILabel alloc] initWithFrame:CGRectMake(30, 300, 50, 30)];    name.text = @"姓 名:";    name.textAlignment = NSTextAlignmentCenter;    [self.view addSubview:name];    [name release];        self.nameTF = [[UITextField alloc] initWithFrame:CGRectMake(100, 300, 150, 30)];    self.nameTF.backgroundColor = [UIColor lightGrayColor];    self.nameTF.layer.borderWidth = 1;    self.nameTF.layer.cornerRadius = 10;    self.nameTF.layer.masksToBounds = YES;    self.nameTF.clearsOnBeginEditing = YES;    self.nameTF.delegate = self;    [self.view addSubview:self.nameTF];    [_nameTF release];        UILabel *sex = [[UILabel alloc] initWithFrame:CGRectMake(30, 350, 50, 30)];    sex.text = @"性 别:";    sex.textAlignment = NSTextAlignmentCenter;    [self.view addSubview:sex];    [sex release];        self.sexTF = [[UITextField alloc] initWithFrame:CGRectMake(100, 350, 150, 30)];    self.sexTF.backgroundColor = [UIColor lightGrayColor];    self.sexTF.layer.borderWidth = 1;    self.sexTF.layer.cornerRadius = 10;    self.sexTF.layer.masksToBounds = YES;    self.sexTF.clearsOnBeginEditing = YES;    self.sexTF.delegate = self;    [self.view addSubview:self.sexTF];    [_sexTF release];        UILabel *hobby = [[UILabel alloc] initWithFrame:CGRectMake(30, 400, 50, 30)];    hobby.text = @"爱 好:";    hobby.textAlignment = NSTextAlignmentCenter;    [self.view addSubview:hobby];    [hobby release];        self.hobbyTF = [[UITextField alloc] initWithFrame:CGRectMake(100, 400, 150, 30)];    self.hobbyTF.backgroundColor = [UIColor lightGrayColor];    self.hobbyTF.layer.borderWidth = 1;    self.hobbyTF.layer.cornerRadius = 10;    self.hobbyTF.layer.masksToBounds = YES;    self.hobbyTF.clearsOnBeginEditing = YES;    self.hobbyTF.delegate = self;    [self.view addSubview:self.hobbyTF];    [_hobbyTF release];        UILabel *phone = [[UILabel alloc] initWithFrame:CGRectMake(30, 450, 50, 30)];    phone.text = @"电 话:";    name.textAlignment = NSTextAlignmentCenter;    [self.view addSubview:phone];    [phone release];        self.phoneTF = [[UITextField alloc] initWithFrame:CGRectMake(100, 450, 150, 30)];    self.phoneTF.backgroundColor = [UIColor lightGrayColor];    self.phoneTF.layer.borderWidth = 1;    self.phoneTF.layer.cornerRadius = 10;    self.phoneTF.layer.masksToBounds = YES;    self.phoneTF.clearsOnBeginEditing = YES;    self.phoneTF.delegate = self;    [self.view addSubview:self.phoneTF];    [_phoneTF release];        UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];    [button setTitle:@"添加" forState:UIControlStateNormal];    button.frame = CGRectMake(200, 480, 50, 30);    [self.view addSubview:button];    [button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];}- (void)click:(UIButton *)but{    UIScrollView *scrollView = (UIScrollView *)[self.view viewWithTag:1000];    NSString *picName = [NSString stringWithFormat:@"%ld.jpg", ((NSInteger)scrollView.contentOffset.x / 200 + 1)];        // 3.设置触发方法    [self.delegate addName:self.nameTF.text Sex:self.sexTF.text Hobby:self.hobbyTF.text Phone:self.phoneTF.text ImageName:picName];    [self.navigationController popToRootViewControllerAnimated:YES];}- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{    if (textField.frame.origin.y > HEIGHT / 2 ) {        CGFloat height = textField.frame.origin.y - HEIGHT / 2;        self.view.center = CGPointMake(self.view.center.x, self.view.center.y - height);    }    return YES;}- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{    // 整个是在移动self.view,父视图的移动会让所有的子视图一同移动,而且相对父视图的坐标位置不会发生变化,所以可以沿用上一个方法的判断    if (textField.frame.origin.y > HEIGHT / 2) {        CGFloat height = textField.frame.origin.y - HEIGHT / 2;        self.view.center = CGPointMake(self.view.center.x, self.view.center.y + height);    }    return YES;}- (BOOL)textFieldShouldReturn:(UITextField *)textField{    [self.nameTF becomeFirstResponder];    [self.sexTF becomeFirstResponder];    [self.hobbyTF becomeFirstResponder];    [self.phoneTF becomeFirstResponder];    return YES;}- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{    [self.nameTF resignFirstResponder];    [self.sexTF resignFirstResponder];    [self.hobbyTF resignFirstResponder];    [self.phoneTF resignFirstResponder];}- (void)didReceiveMemoryWarning {    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}/*#pragma mark - Navigation// In a storyboard-based application, you will often want to do a little preparation before navigation- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {    // Get the new view controller using [segue destinationViewController].    // Pass the selected object to the new view controller.}*/@end

////  ChangeViewController.h//  UI0810通讯录加强版////  Created by dllo on 15/8/11.//  Copyright (c) 2015年 Clare. All rights reserved.//#import <UIKit/UIKit.h>// 声明有这个类@class Student;@protocol ChangeViewController <NSObject>// 1.声明一份属性//- (void)changeName:(NSString *)name//               Sex:(NSString *)sex//             Hobby:(NSString *)hobby//             Phone:(NSString *)phone//         ImageName:(NSString *)imageName;- (void)changeStudent:(Student *)stu                  row:(NSInteger)row;@end@interface ChangeViewController : UIViewController// 2.设置代理人属性@property(nonatomic ,assign)id<ChangeViewController>deleagte;@property(nonatomic, retain)NSMutableArray *arrC;@property(nonatomic, assign)NSInteger row;@end

////  ChangeViewController.m//  UI0810通讯录加强版////  Created by dllo on 15/8/11.//  Copyright (c) 2015年 Clare. All rights reserved.//#import "ChangeViewController.h"#import "Student.h"#define HEIGHT self.view.frame.size.height@interface ChangeViewController ()<UITextFieldDelegate>@property(nonatomic, retain)UITextField *nameTF;@property(nonatomic, retain)UITextField *sexTF;@property(nonatomic, retain)UITextField *hobbyTF;@property(nonatomic, retain)UITextField *phoneTF;@property(nonatomic, retain)UIButton *changeButton;@property(nonatomic, retain)UIImageView *imageView;@end@implementation ChangeViewController- (void)dealloc{    [_arrC release];    [_nameTF release];    [_sexTF release];    [_hobbyTF release];    [_phoneTF release];    [_imageView release];    [_changeButton release];    [super dealloc];}- (void)viewDidLoad {    [super viewDidLoad];    // Do any additional setup after loading the view.    self.view.backgroundColor = [UIColor whiteColor];//    self.imageView.image = [UIImage imageNamed:[self.arrC[self.row] imageName]];    self.imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[self.arrC[self.row] imageName]]];    self.imageView.frame = CGRectMake(100, 50, 200, 200);    [self.view addSubview:self.imageView];    [_imageView release];        UILabel *nameLable = [[UILabel alloc] initWithFrame:CGRectMake(100, 300, 50, 30)];    nameLable.text = @"姓 名:";    nameLable.textAlignment = NSTextAlignmentCenter;    [self.view addSubview:nameLable];    [nameLable release];        self.nameTF = [[UITextField alloc] initWithFrame:CGRectMake(160, 300, 150, 30)];    self.nameTF.text = [self.arrC[self.row] name];    self.nameTF.backgroundColor = [UIColor lightGrayColor];    self.nameTF.layer.borderWidth = 1;    self.nameTF.layer.cornerRadius = 10;    self.nameTF.layer.masksToBounds = YES;    [self.view addSubview:self.nameTF];    self.nameTF.clearsOnBeginEditing = YES;    self.nameTF.delegate = self;    [self.nameTF release];            UILabel *sexLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 350, 50, 30)];    sexLabel.text = @"性 别";    sexLabel.textAlignment = NSTextAlignmentCenter;    [self.view addSubview:sexLabel];    [sexLabel release];        self.sexTF = [[UITextField alloc] initWithFrame:CGRectMake(160, 350, 150, 30)];    self.sexTF.text = [self.arrC[self.row] sex];    self.sexTF.backgroundColor = [UIColor lightGrayColor];    self.sexTF.layer.borderWidth = 1;    self.sexTF.layer.cornerRadius = 10;    self.sexTF.layer.masksToBounds = YES;    [self.view addSubview:self.sexTF];    self.sexTF.clearsOnBeginEditing = YES;    self.sexTF.delegate = self;    [self.sexTF release];        UILabel *hobbyLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 400, 50, 30)];    hobbyLabel.text = @"爱好";    hobbyLabel.textAlignment = NSTextAlignmentCenter;    [self.view addSubview:hobbyLabel];    [hobbyLabel release];        self.hobbyTF = [[UITextField alloc] initWithFrame:CGRectMake(160, 400, 150, 30)];    self.hobbyTF.text = [self.arrC[self.row] hobby];    self.hobbyTF.backgroundColor = [UIColor lightGrayColor];    self.hobbyTF.layer.borderWidth = 1;    self.hobbyTF.layer.cornerRadius = 10;    self.hobbyTF.layer.masksToBounds = YES;    [self.view addSubview:self.hobbyTF];    self.hobbyTF.clearsOnBeginEditing = YES;    self.hobbyTF.delegate = self;    [self.hobbyTF release];            UILabel *phoneLable = [[UILabel alloc] initWithFrame:CGRectMake(100, 450, 50, 30)];    phoneLable.text = @"电 话:";    phoneLable.textAlignment = NSTextAlignmentCenter;    [self.view addSubview:phoneLable];    [phoneLable release];        self.phoneTF = [[UITextField alloc] initWithFrame:CGRectMake(160, 450, 150, 30)];    self.phoneTF.text =[self.arrC[self.row] phone];    self.phoneTF.backgroundColor = [UIColor lightGrayColor];    self.phoneTF.layer.borderWidth = 1;    self.phoneTF.layer.cornerRadius = 10;    self.phoneTF.layer.masksToBounds = YES;    [self.view addSubview:self.phoneTF];    self.phoneTF.clearsOnBeginEditing = YES;    self.phoneTF.delegate = self;    [self.phoneTF release];            self.changeButton = [UIButton buttonWithType:UIButtonTypeSystem];    [self.changeButton setTitle:@"编 辑" forState:UIControlStateNormal];    self.changeButton.frame = CGRectMake(200, 500, 50, 40);    [self.view addSubview:self.changeButton];    [self.changeButton addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];}- (void)click:(UIButton *)button{    Student *stu = [[Student alloc] init];    stu.name = self.nameTF.text;    stu.sex = self.sexTF.text;    stu.hobby = self.hobbyTF.text;    stu.phone = self.phoneTF.text;    stu.imageName = [self.arrC[self.row] imageName];    [self.deleagte changeStudent:stu row:self.row];    [self.navigationController popToRootViewControllerAnimated:YES];    [stu release];}- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{    if (textField.frame.origin.y > HEIGHT / 2 ) {        CGFloat height = textField.frame.origin.y - HEIGHT / 2;        self.view.center = CGPointMake(self.view.center.x, self.view.center.y - height);    }    return YES;}- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{    // 整个是在移动self.view,父视图的移动会让所有的子视图一同移动,而且相对父视图的坐标位置不会发生变化,所以可以沿用上一个方法的判断    if (textField.frame.origin.y > HEIGHT / 2) {        CGFloat height = textField.frame.origin.y - HEIGHT / 2;        self.view.center = CGPointMake(self.view.center.x, self.view.center.y + height);    }    return YES;}- (BOOL)textFieldShouldReturn:(UITextField *)textField{    [self.nameTF becomeFirstResponder];    [self.sexTF becomeFirstResponder];    [self.hobbyTF becomeFirstResponder];    [self.phoneTF becomeFirstResponder];    return YES;}- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{    [self.nameTF resignFirstResponder];    [self.sexTF resignFirstResponder];    [self.hobbyTF resignFirstResponder];    [self.phoneTF resignFirstResponder];}- (void)didReceiveMemoryWarning {    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}/*#pragma mark - Navigation// In a storyboard-based application, you will often want to do a little preparation before navigation- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {    // Get the new view controller using [segue destinationViewController].    // Pass the selected object to the new view controller.}*/@end

////  ManCell.h//  UI0810通讯录加强版////  Created by dllo on 15/8/10.//  Copyright (c) 2015年 Clare. All rights reserved.//#import <UIKit/UIKit.h>@interface ManCell : UITableViewCell@property(nonatomic, retain)UIImageView *leftImage;@property(nonatomic, retain)UILabel *nameLabel;@property(nonatomic, retain)UILabel *sexLabel;@property(nonatomic, retain)UILabel *hobbyLabel;@property(nonatomic, retain)UILabel *phoneLabel;@end

////  ManCell.m//  UI0810通讯录加强版////  Created by dllo on 15/8/10.//  Copyright (c) 2015年 Clare. All rights reserved.//#import "ManCell.h"@interface ManCell()@property(nonatomic, retain)UIView *view1;@end@implementation ManCell- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];    if (self) {        [self createView];    }    return self;}- (void)createView{    self.view1 = [[UIView alloc] init];    self.view1.backgroundColor = [UIColor whiteColor];    [self.contentView addSubview:self.view1];    [self.view1 release];    self.view1.layer.cornerRadius = 15;    self.view1.layer.masksToBounds = YES;        self.contentView.backgroundColor = [UIColor colorWithRed:152 / 255.0 green:251 / 255.0 blue:152 / 255.0 alpha:1];    self.leftImage = [[UIImageView alloc] init];    self.leftImage.backgroundColor = [UIColor lightGrayColor];    [self.contentView addSubview:self.leftImage];    [_leftImage release];        self.nameLabel = [[UILabel alloc] init];    self.nameLabel.backgroundColor = [UIColor lightGrayColor];    [self.contentView addSubview:self.nameLabel];    [_nameLabel release];        self.sexLabel = [[UILabel alloc] init];    self.sexLabel.backgroundColor = [UIColor lightGrayColor];    [self.contentView addSubview:self.sexLabel];    [_sexLabel release];        self.hobbyLabel = [[UILabel alloc] init];    self.hobbyLabel.backgroundColor = [UIColor lightGrayColor];    [self.contentView addSubview:self.hobbyLabel];    [_hobbyLabel release];        self.phoneLabel = [[UILabel alloc] init];    self.phoneLabel.backgroundColor = [UIColor lightGrayColor];    [self.contentView addSubview:self.phoneLabel];    [_phoneLabel release];    }- (void)layoutSubviews{    [super layoutSubviews];    self.view1.frame = CGRectMake(10, 5, self.contentView.frame.size.width - 20, self.contentView.frame.size.height - 20);    self.leftImage.frame = CGRectMake(30, 50, 100, 100);    self.nameLabel.frame = CGRectMake(150, 30, 150, 30);    self.sexLabel.frame = CGRectMake(150, 80, 150, 30);    self.hobbyLabel.frame = CGRectMake(150, 130, 150, 30);    self.phoneLabel.frame = CGRectMake(150, 180, 150, 30);}- (void)dealloc{    [_leftImage release];    [_nameLabel release];    [_sexLabel release];    [_hobbyLabel release];    [_phoneLabel release];    [super dealloc];}- (void)awakeFromNib {    // Initialization code}- (void)setSelected:(BOOL)selected animated:(BOOL)animated {    [super setSelected:selected animated:animated];    // Configure the view for the selected state}@end

////  WomanCell.h//  UI0810通讯录加强版////  Created by dllo on 15/8/10.//  Copyright (c) 2015年 Clare. All rights reserved.//#import <UIKit/UIKit.h>@interface WomanCell : UITableViewCell@property(nonatomic, retain)UILabel *name;@property(nonatomic, retain)UILabel *sex;@property(nonatomic, retain)UILabel *hobby;@property(nonatomic, retain)UILabel *phone;@property(nonatomic, retain)UIImageView *rightImage;@end

////  WomanCell.m//  UI0810通讯录加强版////  Created by dllo on 15/8/10.//  Copyright (c) 2015年 Clare. All rights reserved.//#import "WomanCell.h"@interface WomanCell ()@property(nonatomic, retain)UIView *view2;@end@implementation WomanCell- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];    if (self) {        [self createView];    }    return self;}- (void)createView{    self.view2 = [[UIView alloc] init];    self.view2.backgroundColor = [UIColor whiteColor];    [self.contentView addSubview:self.view2];    [self.view2 release];    self.view2.layer.cornerRadius = 15;    self.view2.layer.masksToBounds = YES;        self.contentView.backgroundColor = [UIColor colorWithRed:255 / 255.0 green:0 / 255.0 blue:255 / 255.0 alpha:1];    self.name = [[UILabel alloc] init];    self.name.backgroundColor = [UIColor lightGrayColor];    [self.contentView addSubview:self.name];    [_name release];        self.sex = [[UILabel alloc] init];    self.sex.backgroundColor = [UIColor lightGrayColor];    [self.contentView addSubview:self.sex];    [_sex release];        self.hobby = [[UILabel alloc] init];    self.hobby.backgroundColor = [UIColor lightGrayColor];    [self.contentView addSubview:self.hobby];    [_hobby release];        self.phone = [[UILabel alloc] init];    self.phone.backgroundColor = [UIColor lightGrayColor];    [self.contentView addSubview:self.phone];    [_phone release];        self.rightImage = [[UIImageView alloc] init];    self.rightImage.backgroundColor = [UIColor lightGrayColor];    [self.contentView addSubview:self.rightImage];    [_rightImage release];}- (void)layoutSubviews{    [super layoutSubviews];    self.view2.frame = CGRectMake(10, 5, self.contentView.frame.size.width - 20, self.contentView.frame.size.height - 20);    self.name.frame = CGRectMake(20, 30, 150, 30);        self.sex.frame = CGRectMake(20, 80, 150, 30);        self.hobby.frame = CGRectMake(20, 140, 150, 30);        self.phone.frame = CGRectMake(20, 200, 150, 30);        self.rightImage.frame = CGRectMake(200, 50, 100, 100);}- (void)dealloc{    [_name release];    [_sex release];    [_hobby release];    [_phone release];    [_rightImage release];    [_view2  release];    [super dealloc];}- (void)awakeFromNib {    // Initialization code}- (void)setSelected:(BOOL)selected animated:(BOOL)animated {    [super setSelected:selected animated:animated];    // Configure the view for the selected state}@end

////  Student.h//  UI0810通讯录加强版////  Created by dllo on 15/8/10.//  Copyright (c) 2015年 Clare. All rights reserved.//#import <Foundation/Foundation.h>@interface Student : NSObject@property(nonatomic, copy)NSString *name;@property(nonatomic, copy)NSString *sex;@property(nonatomic, copy)NSString *hobby;@property(nonatomic, copy)NSString *phone;@property(nonatomic, copy)NSString *imageName;@end

////  Student.m//  UI0810通讯录加强版////  Created by dllo on 15/8/10.//  Copyright (c) 2015年 Clare. All rights reserved.//#import "Student.h"@implementation Student- (void)dealloc{    [_name release];    [_sex release];    [_hobby release];    [_phone release];    [_imageName release];    [super dealloc];}- (void)setValue:(id)value forUndefinedKey:(NSString *)key{    }@end


0 0
原创粉丝点击