自定义cell 通讯录

来源:互联网 发布:淘宝代购延长收货 编辑:程序博客网 时间:2024/06/05 20:24
////  AppDelegate.h//  810 作业 通讯录////  Created by dllo on 15/8/10.//  Copyright (c) 2015年 flg. All rights reserved.//#import <UIKit/UIKit.h>@interface AppDelegate : UIResponder <UIApplicationDelegate>@property (strong, nonatomic) UIWindow *window;@end
////  AppDelegate.m//  810 作业 通讯录////  Created by dllo on 15/8/10.//  Copyright (c) 2015年 flg. 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 lightGrayColor];    [self.window makeKeyAndVisible];    [_window release];        MainViewController *mainVC=[[MainViewController alloc] init];    UINavigationController *naVC=[[UINavigationController alloc] initWithRootViewController:mainVC];    self.window.rootViewController=naVC;    [mainVC release];    [naVC release];    return YES;}- (void)applicationWillResignActive:(UIApplication *)application {    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.}- (void)applicationDidEnterBackground:(UIApplication *)application {    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.}- (void)applicationWillEnterForeground:(UIApplication *)application {    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.}- (void)applicationDidBecomeActive:(UIApplication *)application {    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.}- (void)applicationWillTerminate:(UIApplication *)application {    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.}@end

////  MainViewController.h//  810 作业 通讯录////  Created by dllo on 15/8/10.//  Copyright (c) 2015年 flg. All rights reserved.//#import <UIKit/UIKit.h>@interface MainViewController : UIViewController@end

////  MainViewController.m//  810 作业 通讯录////  Created by dllo on 15/8/10.//  Copyright (c) 2015年 flg. All rights reserved.//#import "MainViewController.h"#import "ManTableViewCell.h"#import "studentArr.h"#import "WomenTableViewCell.h"#import "informationViewController.h"#import "addViewController.h"///...4.签订协议@interface MainViewController ()<UITableViewDataSource,UITableViewDelegate,informationViewControllerdelegate,addViewControllerdelegate>@property(nonatomic,retain)UITableView *tableview;///@property(nonatomic,retain)NSMutableArray *arr;@property(nonatomic,retain)NSMutableArray *picArr;@property(nonatomic,retain)studentArr *stu;@property(nonatomic,retain)studentArr *stus;@property(nonatomic,retain)ManTableViewCell *cell;@property(nonatomic,retain)WomenTableViewCell *cell1;@end@implementation MainViewController- (void)dealloc{    [_tableview release];    [_arr release];    [_stu release];    [_picArr release];    [_cell release];    [_cell1 release];    [_stus release];    [super dealloc];}- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{    self=[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];    if (self) {        [self createData];    }    return self;}- (void)createData{    NSString *path=[[NSBundle mainBundle] pathForResource:@"StudentArr" ofType:@"plist"];    self.arr=[[NSMutableArray alloc] init];    //////////////////////////////////////    NSMutableArray *arr=[NSMutableArray arrayWithContentsOfFile:path];        for (NSMutableDictionary *dic in arr) {        self.stu=[[studentArr alloc] init];        [self.stu setValuesForKeysWithDictionary:dic];        [self.arr addObject:self.stu];        [self.stu release];    }//////////    self.picArr=[NSMutableArray array];    for (NSInteger i=0; i<self.arr.count; i++) {        NSString *str=[NSString stringWithFormat:@"%ld.jpg",i];        [self.picArr addObject:str];    }}- (void)viewDidLoad {    [super viewDidLoad];    // Do any additional setup after loading the view.    self.title=@"通讯录";    self.navigationController.navigationBar.translucent=NO;    self.navigationController.navigationBar.barTintColor=[UIColor colorWithRed:255/255.0 green:212/255.0 blue:0 alpha:1];    self.view.backgroundColor=[UIColor colorWithRed:255/255.0 green:212/255.0 blue:0 alpha:1];    self.tableview=[[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-64) style:UITableViewStylePlain];    [self.view addSubview:self.tableview];    [_tableview release];    self.tableview.rowHeight=200;    self.tableview.dataSource=self;    self.tableview.delegate=self;//去除cell之间的分割线    self.tableview.separatorStyle=UITableViewCellSeparatorStyleNone;    self.navigationItem.rightBarButtonItem=[[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"6.png"] style:UIBarButtonItemStylePlain target:self action:@selector(rightBarButtonItemAxtion:)] autorelease];}/////必须实现的协议方法1//////////////////////////////////////-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{    return self.arr.count;}/////必须实现的协议方法2./////////////////////////////////////-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{    self.stus=self.arr[indexPath.row];    if ([self.stus.sex isEqualToString:@"男"]) {    static NSString *reuse=@"reuse";   self.cell=[tableView dequeueReusableCellWithIdentifier:reuse];    if (!self.cell) {        self.cell=[[[ManTableViewCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier:reuse] autorelease];    }    self.cell.manNameLabel.text=self.stus.name;    self.cell.manPhoneLabel.text=self.stus.phone;    self.cell.manSexLabel.text=self.stus.sex;    self.cell.manHobbyLabel.text=self.stus.hobby;////添加图片方法一>>>>>>//    NSString *str=[NSString stringWithFormat:@"%ld.jpg",indexPath.row];//    cell.image.image=[UIImage imageNamed:str];////添加图片方法二......承接54行,,将图片名添加到数组中        self.cell.image.image=[UIImage imageNamed:self.picArr[indexPath.row]];    return self.cell;    }else if([self.stus.sex isEqualToString:@"女"]){        static NSString *reuse1=@"reuse1";        self.cell1=[tableView dequeueReusableCellWithIdentifier:reuse1];        if (!self.cell1) {            self.cell1=[[[WomenTableViewCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier:reuse1] autorelease];        }        self.cell1.manNameLabel.text=self.stus.name;        self.cell1.manPhoneLabel.text=self.stus.phone;        self.cell1.manSexLabel.text=self.stus.sex;        self.cell1.manHobbyLabel.text=self.stus.hobby;        //NSString *str=[NSString stringWithFormat:@"%ld.jpg",indexPath.row];       // self.cell1.image.image=[UIImage imageNamed:str];        self.cell1.image.image=[UIImage imageNamed:self.picArr[indexPath.row]];        return self.cell1;    }    return nil;}////tableview的点击方法//////////////////////////////- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{    informationViewController *information=[[informationViewController alloc] init];    information.imageStr=[NSString stringWithFormat:@"%ld.jpg",indexPath.row];    ///...5.设置代理人    information.delegate=self;    NSLog(@"设置代理人");    [self.navigationController pushViewController:information animated:YES];    [information release];///由第一页向详情页传值    information.informationArr=self.arr;    information.index=indexPath.row;}///...6.协议方法的实现- (void)change:(studentArr *)change{    if ([change.sex isEqualToString:@"男"]) {        self.cell.manNameLabel.text=change.name;        self.cell.manPhoneLabel.text=change.phone;        self.cell.manSexLabel.text=change.sex;        self.cell.manHobbyLabel.text=change.hobby;        NSLog(@"_____________%@",change.name);    }else{        self.cell1.manNameLabel.text=change.name;        self.cell1.manPhoneLabel.text=change.phone;        self.cell1.manSexLabel.text=change.sex;        self.cell1.manHobbyLabel.text=change.hobby;        NSLog(@"+++++++++++++++++%@",change.name);    }}//添加按钮- (void)rightBarButtonItemAxtion:(UIButton *)button{    addViewController *add=[[addViewController alloc] init];    ///////5..............    add.delegate=self;    NSLog(@"设置代理");    [self.navigationController pushViewController:add animated:YES];    [add release];}/////////6...........- (void)add:(studentArr *)addstu{    [self.arr addObject:addstu];    self.stus.name=addstu.name;    self.stus.phone=addstu.phone;    self.stus.sex=addstu.sex;    self.stus.hobby=addstu.hobby;//        if ([addstu.sex isEqualToString:@"男"]) {//            self.cell.manNameLabel.text=addstu.name;//            self.cell.manPhoneLabel.text=addstu.phone;//            self.cell.manSexLabel.text=addstu.sex;//            self.cell.manHobbyLabel.text=addstu.hobby;//            NSLog(@"_____________%@",addstu.name);//        }else{//            self.cell1.manNameLabel.text=addstu.name;//            self.cell1.manPhoneLabel.text=addstu.phone;//            self.cell1.manSexLabel.text=addstu.sex;//            self.cell1.manHobbyLabel.text=addstu.hobby;//            NSLog(@"+++++++++++++++++%@",addstu.name);//        }   [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

////  informationViewController.h//  810 作业 通讯录////  Created by dllo on 15/8/10.//  Copyright (c) 2015年 flg. All rights reserved.//#import <UIKit/UIKit.h>#import "studentArr.h"///1...签协议@protocol informationViewControllerdelegate<NSObject>//- (void)changeDic:(NSMutableDictionary *)changeDic;-(void)change:(studentArr *)change;@end@interface informationViewController : UIViewController@property(nonatomic,copy)NSString *imageStr;//@property(nonatomic,retain)studentArr *student;@property(nonatomic,retain)NSMutableArray *informationArr;@property(nonatomic,assign)NSInteger index;///2...设置协议人属性@property(nonatomic,assign)id<informationViewControllerdelegate>delegate;@end

////  informationViewController.m//  810 作业 通讯录////  Created by dllo on 15/8/10.//  Copyright (c) 2015年 flg. All rights reserved.//#import "informationViewController.h"#import "studentArr.h"@interface informationViewController ()<UITextFieldDelegate>@property(nonatomic,retain)UIImageView *image;@property(nonatomic,retain)UITextField *nameTextField;@property(nonatomic,retain)UITextField *phoneTextField;@property(nonatomic,retain)UITextField *sexTextField;@property(nonatomic,retain)UITextField *hobbyTextField;@property(nonatomic,retain)UILabel *nameLabel;@property(nonatomic,retain)UILabel *phoneLabel;@property(nonatomic,retain)UILabel *sexLabel;@property(nonatomic,retain)UILabel *hobbyLabel;@property(nonatomic,retain)UIButton *saveButton;@end@implementation informationViewController- (void)dealloc{    [_image release];    [_nameTextField release];    [_phoneTextField release];    [_sexTextField release];    [_hobbyTextField release];    [_informationArr release];    [_saveButton release];    [_nameLabel release];    [_phoneLabel release];    [_sexLabel release];    [_hobbyLabel release];    [_imageStr release];    //[_student release];    [super dealloc];}- (void)viewDidLoad {    [super viewDidLoad];    // Do any additional setup after loading the view.    ///大头像    self.view.backgroundColor=[UIColor colorWithRed:255/255.0 green:212/255.0 blue:0 alpha:1];    self.image=[[UIImageView alloc] initWithImage:[UIImage imageNamed:self.imageStr]];    self.image.frame=CGRectMake(80, 80, 200, 200);    [self.view addSubview:self.image];    [_image release];    ///姓名label    self.nameLabel=[[UILabel alloc] initWithFrame:CGRectMake(50, 300, 50, 30)];    [self.view addSubview:self.nameLabel];    self.nameLabel.layer.cornerRadius=10;    self.nameLabel.layer.masksToBounds=YES;    self.nameLabel.text=@"姓名";    [_nameLabel release];    ///姓名textfield    self.nameTextField=[[UITextField alloc] initWithFrame:CGRectMake(100, 300, 200, 30)];    self.nameTextField.backgroundColor=[UIColor lightGrayColor];    self.nameTextField.layer.cornerRadius=10;    self.nameTextField.layer.masksToBounds=YES;    [self.view addSubview:self.nameTextField];    self.nameTextField.delegate=self;    [_nameTextField release];    ///电话label    self.phoneLabel=[[UILabel alloc] initWithFrame:CGRectMake(50, 350, 50, 30)];    [self.view addSubview:self.phoneLabel];    self.phoneLabel.layer.cornerRadius=10;    self.phoneLabel.layer.masksToBounds=YES;    self.phoneLabel.text=@"电话";    [_phoneLabel release];    ///电话textfield    self.phoneTextField=[[UITextField alloc] initWithFrame:CGRectMake(100, 350, 200, 30)];    self.phoneTextField.backgroundColor=[UIColor lightGrayColor];    self.phoneTextField.layer.cornerRadius=10;    self.phoneTextField.layer.masksToBounds=YES;    [self.view addSubview:self.phoneTextField];    self.phoneTextField.delegate=self;    [_phoneTextField release];    ///性别label    self.sexLabel=[[UILabel alloc] initWithFrame:CGRectMake(50, 400, 50, 30)];    [self.view addSubview:self.sexLabel];    self.sexLabel.layer.cornerRadius=10;    self.sexLabel.layer.masksToBounds=YES;    self.sexLabel.text=@"性别";    [_sexLabel release];    ///性别textfield    self.sexTextField=[[UITextField alloc] initWithFrame:CGRectMake(100, 400, 200, 30)];    self.sexTextField.backgroundColor=[UIColor lightGrayColor];    self.sexTextField.layer.cornerRadius=10;    self.sexTextField.layer.masksToBounds=YES;    [self.view addSubview:self.sexTextField];    self.sexTextField.delegate=self;    [_sexTextField release];    ///爱好label    self.hobbyLabel=[[UILabel alloc] initWithFrame:CGRectMake(50, 450, 50, 30)];    [self.view addSubview:self.hobbyLabel];    self.hobbyLabel.layer.cornerRadius=10;    self.hobbyLabel.layer.masksToBounds=YES;    self.hobbyLabel.text=@"爱好";    [_hobbyLabel release];    ///爱好textfield    self.hobbyTextField=[[UITextField alloc] initWithFrame:CGRectMake(100, 450, 200, 30)];    self.hobbyTextField.backgroundColor=[UIColor lightGrayColor];    self.hobbyTextField.layer.cornerRadius=10;    self.hobbyTextField.layer.masksToBounds=YES;    [self.view addSubview:self.hobbyTextField];    self.hobbyTextField.delegate=self;    [_hobbyTextField release];    ///保存按钮    self.saveButton=[UIButton buttonWithType:UIButtonTypeSystem];    self.saveButton.frame=CGRectMake(200, 500, 50, 30);    [self.saveButton setTitle:@"保存" forState:UIControlStateNormal];    self.saveButton.layer.cornerRadius=10;    self.saveButton.layer.masksToBounds=YES;    [self.view addSubview:self.saveButton];    self.saveButton.backgroundColor=[UIColor orangeColor];    [self.saveButton addTarget:self action:@selector(saveButtonAction:) forControlEvents:UIControlEventTouchUpInside];    studentArr *stu=self.informationArr[self.index];    self.nameTextField.text=stu.name;    self.phoneTextField.text=stu.phone;    self.sexTextField.text=stu.sex;    self.hobbyTextField.text=stu.hobby;   }//点击空白回收键盘- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{    [self.nameTextField resignFirstResponder];    [self.phoneTextField resignFirstResponder];    [self.sexTextField resignFirstResponder];    [self.hobbyTextField resignFirstResponder];}- (void)saveButtonAction:(UIButton *)button{///3..执行协议方法//    NSMutableDictionary *dic=[NSMutableDictionary dictionaryWithObjectsAndKeys:self.nameTextField.text,@"name",self.phoneTextField.text,@"phone",self.sexTextField.text,@"sex",self.hobbyTextField.text,@"hobby", nil];//    [self.delegate changeDic:dic];//    [self.navigationController popViewControllerAnimated:YES];//    NSLog(@"执行协议");    studentArr *stu=[[studentArr alloc] init];    stu.name=self.nameTextField.text;    stu.phone=self.phoneTextField.text;    stu.sex=self.sexTextField.text;    stu.hobby=self.hobbyTextField.text;    [self.delegate change:stu];    [self.navigationController popViewControllerAnimated:YES];}- (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//  810 作业 通讯录////  Created by dllo on 15/8/11.//  Copyright (c) 2015年 flg. All rights reserved.//#import <UIKit/UIKit.h>#import "studentArr.h"@protocol addViewControllerdelegate<NSObject>//1- (void)add:(studentArr *)addstu;@end@interface addViewController : UIViewController//2@property(nonatomic,assign)id<addViewControllerdelegate>delegate;@end

////  addViewController.m//  810 作业 通讯录////  Created by dllo on 15/8/11.//  Copyright (c) 2015年 flg. All rights reserved.//#import "addViewController.h"#import "studentArr.h"@interface addViewController ()<UITextFieldDelegate>@property(nonatomic,retain)UITextField *nameTextField;@property(nonatomic,retain)UITextField *phoneTextField;@property(nonatomic,retain)UITextField *sexTextField;@property(nonatomic,retain)UITextField *hobbyTextField;@property(nonatomic,retain)UILabel *nameLabel;@property(nonatomic,retain)UILabel *phoneLabel;@property(nonatomic,retain)UILabel *sexLabel;@property(nonatomic,retain)UILabel *hobbyLabel;@property(nonatomic,retain)UIButton *saveButton;@property(nonatomic,retain)UIImageView *image;@end@implementation addViewController- (void)dealloc{    [_image release];    [_nameTextField release];    [_phoneTextField release];    [_sexTextField release];    [_hobbyTextField release];    [_saveButton release];    [_nameLabel release];    [_phoneLabel release];    [_sexLabel release];    [_hobbyLabel release];    [super dealloc];}- (void)viewDidLoad {    [super viewDidLoad];    // Do any additional setup after loading the view.    self.view.backgroundColor=[UIColor cyanColor];    ///大头像    self.view.backgroundColor=[UIColor colorWithRed:255/255.0 green:212/255.0 blue:0 alpha:1];    self.image=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"27.jpg"]];    self.image.frame=CGRectMake(80, 80, 200, 200);    [self.view addSubview:self.image];    [_image release];    ///姓名label    self.nameLabel=[[UILabel alloc] initWithFrame:CGRectMake(50, 300, 50, 30)];    [self.view addSubview:self.nameLabel];    self.nameLabel.layer.cornerRadius=10;    self.nameLabel.layer.masksToBounds=YES;    self.nameLabel.text=@"姓名";    [_nameLabel release];    ///姓名textfield    self.nameTextField=[[UITextField alloc] initWithFrame:CGRectMake(100, 300, 200, 30)];    self.nameTextField.backgroundColor=[UIColor lightGrayColor];    self.nameTextField.layer.cornerRadius=10;    self.nameTextField.layer.masksToBounds=YES;    [self.view addSubview:self.nameTextField];    self.nameTextField.delegate=self;    [_nameTextField release];    ///电话label    self.phoneLabel=[[UILabel alloc] initWithFrame:CGRectMake(50, 350, 50, 30)];    [self.view addSubview:self.phoneLabel];    self.phoneLabel.layer.cornerRadius=10;    self.phoneLabel.layer.masksToBounds=YES;    self.phoneLabel.text=@"电话";    [_phoneLabel release];    ///电话textfield    self.phoneTextField=[[UITextField alloc] initWithFrame:CGRectMake(100, 350, 200, 30)];    self.phoneTextField.backgroundColor=[UIColor lightGrayColor];    self.phoneTextField.layer.cornerRadius=10;    self.phoneTextField.layer.masksToBounds=YES;    [self.view addSubview:self.phoneTextField];    self.phoneTextField.delegate=self;    [_phoneTextField release];    ///性别label    self.sexLabel=[[UILabel alloc] initWithFrame:CGRectMake(50, 400, 50, 30)];    [self.view addSubview:self.sexLabel];    self.sexLabel.layer.cornerRadius=10;    self.sexLabel.layer.masksToBounds=YES;    self.sexLabel.text=@"性别";    [_sexLabel release];    ///性别textfield    self.sexTextField=[[UITextField alloc] initWithFrame:CGRectMake(100, 400, 200, 30)];    self.sexTextField.backgroundColor=[UIColor lightGrayColor];    self.sexTextField.layer.cornerRadius=10;    self.sexTextField.layer.masksToBounds=YES;    [self.view addSubview:self.sexTextField];    self.sexTextField.delegate=self;    [_sexTextField release];    ///爱好label    self.hobbyLabel=[[UILabel alloc] initWithFrame:CGRectMake(50, 450, 50, 30)];    [self.view addSubview:self.hobbyLabel];    self.hobbyLabel.layer.cornerRadius=10;    self.hobbyLabel.layer.masksToBounds=YES;    self.hobbyLabel.text=@"爱好";    [_hobbyLabel release];    ///爱好textfield    self.hobbyTextField=[[UITextField alloc] initWithFrame:CGRectMake(100, 450, 200, 30)];    self.hobbyTextField.backgroundColor=[UIColor lightGrayColor];    self.hobbyTextField.layer.cornerRadius=10;    self.hobbyTextField.layer.masksToBounds=YES;    [self.view addSubview:self.hobbyTextField];    self.hobbyTextField.delegate=self;    [_hobbyTextField release];    ///添加按钮    self.saveButton=[UIButton buttonWithType:UIButtonTypeSystem];    self.saveButton.frame=CGRectMake(200, 500, 50, 30);    [self.saveButton setTitle:@"添加" forState:UIControlStateNormal];    self.saveButton.layer.cornerRadius=10;    self.saveButton.layer.masksToBounds=YES;    [self.view addSubview:self.saveButton];    self.saveButton.backgroundColor=[UIColor orangeColor];   [self.saveButton addTarget:self action:@selector(addButtonAction:) forControlEvents:UIControlEventTouchUpInside];}//点击空白回收键盘- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{    [self.nameTextField resignFirstResponder];    [self.phoneTextField resignFirstResponder];    [self.sexTextField resignFirstResponder];    [self.hobbyTextField resignFirstResponder];}- (void)addButtonAction:(UIButton *)button{    studentArr *addstu=[[studentArr alloc] init];    addstu.name=self.nameTextField.text;    NSLog(@"_________________________%@",addstu.name);    addstu.phone=self.phoneTextField.text;    addstu.sex=self.sexTextField.text;    addstu.hobby=self.hobbyTextField.text;/////3.........    [self.delegate add:addstu];    [self.navigationController popViewControllerAnimated:YES];}//实现上下移动显示被遮挡的textfield- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{    if (textField.frame.origin.y>self.view.frame.size.height/2) {        CGFloat height=textField.frame.origin.y-self.view.frame.size.height/2;        self.view.center=CGPointMake(self.view.center.x, self.view.center.y-height);    }    return YES;}//等到编译结束的时候,再让他回到原位-(BOOL)textFieldShouldEndEditing:(UITextField *)textField{    if (textField.frame.origin.y>self.view.frame.size.height/2) {        CGFloat height=textField.frame.origin.y-self.view.frame.size.height/2;        self.view.center=CGPointMake(self.view.center.x, self.view.center.y+height);    }    return YES;}- (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

////  ManTableViewCell.h//  810 作业 通讯录////  Created by dllo on 15/8/10.//  Copyright (c) 2015年 flg. All rights reserved.//#import <UIKit/UIKit.h>@interface ManTableViewCell : UITableViewCell@property(nonatomic,retain)UILabel *label;@property(nonatomic,retain)UIImageView *image;@property(nonatomic,retain)UILabel *manNameLabel;@property(nonatomic,retain)UILabel *manPhoneLabel;@property(nonatomic,retain)UILabel *manSexLabel;@property(nonatomic,retain)UILabel *manHobbyLabel;@end

////  ManTableViewCell.m//  810 作业 通讯录////  Created by dllo on 15/8/10.//  Copyright (c) 2015年 flg. All rights reserved.//#import "ManTableViewCell.h"#define WIDTH self.contentView.frame.size.width#define HEIGHT self.contentView.frame.size.height@implementation ManTableViewCell- (void)dealloc{    [_image release];    [_label release];    [_manNameLabel release];    [_manPhoneLabel release];    [_manSexLabel release];    [_manHobbyLabel release];    [super dealloc];}-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{    [super initWithStyle:style reuseIdentifier:reuseIdentifier];    if (self) {        [self create];    }    return self;}-(void)create{    self.label=[[UILabel alloc] init];    self.label.backgroundColor=[UIColor cyanColor];    self.label.layer.borderWidth=2;    self.label.layer.borderColor=[UIColor yellowColor].CGColor;    self.label.layer.cornerRadius=10;    self.label.layer.masksToBounds=YES;    [self.contentView addSubview:self.label];    [_label release];    self.image=[[UIImageView alloc] init];    //[self.contentView addSubview:self.image];    [self.label addSubview:self.image];    self.image.backgroundColor=[UIColor lightGrayColor];    [_image release];    self.manNameLabel=[[UILabel alloc] init];    //[self.contentView addSubview:self.manNameLabel];    [self.label addSubview:self.manNameLabel];    self.manNameLabel.layer.cornerRadius=10;    self.manNameLabel.layer.masksToBounds=YES;    self.manNameLabel.backgroundColor=[UIColor lightGrayColor];    [_manNameLabel release];    self.manPhoneLabel=[[UILabel alloc] init];    //[self.contentView addSubview:self.manPhoneLabel];    [self.label addSubview:self.manPhoneLabel];    self.manPhoneLabel.layer.cornerRadius=10;    self.manPhoneLabel.layer.masksToBounds=YES;    self.manPhoneLabel.backgroundColor=[UIColor lightGrayColor];    [_manPhoneLabel release];    self.manSexLabel=[[UILabel alloc] init];    //[self.contentView addSubview:self.manSexLabel];    [self.label addSubview:self.manSexLabel];    self.manSexLabel.layer.cornerRadius=10;    self.manSexLabel.layer.masksToBounds=YES;    self.manSexLabel.backgroundColor=[UIColor lightGrayColor];    [_manSexLabel release];    self.manHobbyLabel=[[UILabel alloc] init];    //[self.contentView addSubview:self.manHobbyLabel];    [self.label addSubview:self.manHobbyLabel];    self.manHobbyLabel.layer.cornerRadius=10;    self.manHobbyLabel.layer.masksToBounds=YES;    self.manHobbyLabel.backgroundColor=[UIColor lightGrayColor];    [_manHobbyLabel release];}-(void)layoutSubviews{    [super layoutSubviews];    //////////////    self.label.frame=CGRectMake(10, 10, WIDTH-20, HEIGHT-20);    self.image.frame=CGRectMake(10, 30, 100, 100);    self.manNameLabel.frame=CGRectMake(120, 10, 150, 30);    self.manPhoneLabel.frame=CGRectMake(120, 50, 150, 30);    self.manSexLabel.frame=CGRectMake(120, 90, 150, 30);    self.manHobbyLabel.frame=CGRectMake(120, 130, 150, 30);}- (void)awakeFromNib {    // Initialization code}- (void)setSelected:(BOOL)selected animated:(BOOL)animated {    [super setSelected:selected animated:animated];    // Configure the view for the selected state}@end

////  WomenTableViewCell.h//  810 作业 通讯录////  Created by dllo on 15/8/10.//  Copyright (c) 2015年 flg. All rights reserved.//#import <UIKit/UIKit.h>@interface WomenTableViewCell : UITableViewCell@property(nonatomic,retain)UILabel *label;@property(nonatomic,retain)UIImageView *image;@property(nonatomic,retain)UILabel *manNameLabel;@property(nonatomic,retain)UILabel *manPhoneLabel;@property(nonatomic,retain)UILabel *manSexLabel;@property(nonatomic,retain)UILabel *manHobbyLabel;@end

////  WomenTableViewCell.m//  810 作业 通讯录////  Created by dllo on 15/8/10.//  Copyright (c) 2015年 flg. All rights reserved.//#import "WomenTableViewCell.h"#define WIDTH self.contentView.frame.size.width#define HEIGHT self.contentView.frame.size.height@implementation WomenTableViewCell- (void)dealloc{    [_image release];    [_label release];    [_manNameLabel release];    [_manPhoneLabel release];    [_manSexLabel release];    [_manHobbyLabel release];    [super dealloc];}-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{    [super initWithStyle:style reuseIdentifier:reuseIdentifier];    if (self) {        [self create];    }    return self;}-(void)create{    self.label=[[UILabel alloc] init];    self.label.backgroundColor=[UIColor colorWithRed:221/255.0 green:160/255.0 blue:221/255.0 alpha:1];    self.label.layer.borderWidth=2;    self.label.layer.borderColor=[UIColor greenColor].CGColor;    self.label.layer.cornerRadius=10;    self.label.layer.masksToBounds=YES;    [self.contentView addSubview:self.label];    [_label release];    self.image=[[UIImageView alloc] init];    //[self.contentView addSubview:self.image];    [self.label addSubview:self.image];    self.image.backgroundColor=[UIColor lightGrayColor];    [_image release];    self.manNameLabel=[[UILabel alloc] init];    //[self.contentView addSubview:self.manNameLabel];    [self.label addSubview:self.manNameLabel];    self.manNameLabel.layer.cornerRadius=10;    self.manNameLabel.layer.masksToBounds=YES;    self.manNameLabel.backgroundColor=[UIColor lightGrayColor];    [_manNameLabel release];    self.manPhoneLabel=[[UILabel alloc] init];    //[self.contentView addSubview:self.manPhoneLabel];    [self.label addSubview:self.manPhoneLabel];    self.manPhoneLabel.layer.cornerRadius=10;    self.manPhoneLabel.layer.masksToBounds=YES;    self.manPhoneLabel.backgroundColor=[UIColor lightGrayColor];    [_manPhoneLabel release];    self.manSexLabel=[[UILabel alloc] init];    //[self.contentView addSubview:self.manSexLabel];    [self.label addSubview:self.manSexLabel];    self.manSexLabel.layer.cornerRadius=10;    self.manSexLabel.layer.masksToBounds=YES;    self.manSexLabel.backgroundColor=[UIColor lightGrayColor];    [_manSexLabel release];    self.manHobbyLabel=[[UILabel alloc] init];    //[self.contentView addSubview:self.manHobbyLabel];    [self.label addSubview:self.manHobbyLabel];    self.manHobbyLabel.layer.cornerRadius=10;    self.manHobbyLabel.layer.masksToBounds=YES;    self.manHobbyLabel.backgroundColor=[UIColor lightGrayColor];    [_manHobbyLabel release];}-(void)layoutSubviews{    [super layoutSubviews];    //////////////    self.label.frame=CGRectMake(10, 10, WIDTH-20, HEIGHT-20);    self.image.frame=CGRectMake(WIDTH-130, 30, 100, 100);    self.manNameLabel.frame=CGRectMake(80, 10, 150, 30);    self.manPhoneLabel.frame=CGRectMake(80, 50, 150, 30);    self.manSexLabel.frame=CGRectMake(80, 90, 150, 30);    self.manHobbyLabel.frame=CGRectMake(80, 130, 150, 30);}- (void)awakeFromNib {    // Initialization code}- (void)setSelected:(BOOL)selected animated:(BOOL)animated {    [super setSelected:selected animated:animated];    // Configure the view for the selected state}@end

////  studentArr.h//  810 作业 通讯录////  Created by dllo on 15/8/10.//  Copyright (c) 2015年 flg. All rights reserved.//#import <Foundation/Foundation.h>@interface studentArr : NSObject@property(nonatomic,copy)NSString *name;@property(nonatomic,copy)NSString *phone;@property(nonatomic,copy)NSString *sex;@property(nonatomic,copy)NSString *hobby;@end

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


0 0