往通讯录里添加联系人的时候,有一个功能时添加照片,代码中没有写添加链接,只能通过添加已经拖到xcord里照片的名字来把照片显示出来。

#import "MainViewController.h"
#import "Student.h"
#import "FirstViewController.h"
#import "SecondViewController.h"
@interface MainViewController ()<PassValueDelegate,InsertViewDelegate>@end@implementation MainViewController- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];if (self) {// Custom initializationself.arr = [NSMutableArray array];self.title = @"通讯录";}return self;
}- (void)viewDidLoad
{[super viewDidLoad];// 姓名NSArray *arrName = [NSArray arrayWithObjects:@"小红", @"小华", @"小凯", @"小白", @"小明", @"小博", @"小杨", @"小谢", @"小李", @"小管", @"小美", @"小红", @"小杰",@"小侯", @"小磊", @"莎莎", @"小薛", @"小郑", @"小志", @"小达", @"王贺", @"郭维", @"小童",@"小东", @"小国", nil];// 电话号码NSArray *arrNum = [NSArray arrayWithObjects:@"11111",@"22222",@"33333",@"44444",@"55555",@"66666",@"77777",@"88888",@"999999",@"00000", @"12222", @"13333", @"14444", @"15555", @"16666", @"17777", @"18888",@"19999", @"21111",@"123456", @"432143",@"666543", @"987897", @"555667",@"444333", nil];// 照片for (int i = 0; i < 25; i++) {Student *stu = [[Student alloc]init];stu.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg", i]];stu.name = [arrName objectAtIndex:i];stu.number = [arrNum objectAtIndex:i];[self.arr addObject:stu];[stu release];}self.table = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];self.table.delegate = self;self.table.dataSource = self;self.table.backgroundColor = [UIColor magentaColor];self.table.rowHeight = 40;[self.view addSubview:self.table];// 是否处在编辑状态[_table setEditing:NO animated:YES];// 在bar昨天设置编辑按钮self.navigationItem.leftBarButtonItem = self.editButtonItem;self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"insert.png"] style:UIBarButtonItemStylePlain target:self action:@selector(buttonAction:)]autorelease];[_table release];// Do any additional setup after loading the view.
}- (void)dealloc
{[_arr release];[_table release];[super dealloc];
}- (void)buttonAction:(UINavigationBar *)insert
{SecondViewController *second = [[SecondViewController alloc]init];second.delegate = self;[self.navigationController pushViewController:second animated:YES];}/// 添加方法
- (void)insertStu:(Student *)stu;
{[self.arr insertObject:stu atIndex:0];[[self.view.subviews firstObject]reloadData];
}// viewController的编辑按钮的点击方法
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{[super setEditing:editing animated:animated];[_table setEditing:editing animated:animated];}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{return self.arr.count;
}- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{// 获取到原位置的这条数据NSString *name = [[self.arr objectAtIndex:sourceIndexPath.row] retain];// 从原来的位置 删除掉这条数据[self.arr removeObjectAtIndex:sourceIndexPath.row];// 添加到目的位置[self.arr insertObject:name atIndex:destinationIndexPath.row];[name release];
}// 移动
// 设定某一行能否被移动
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{return YES;
}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{static NSString *str = @"str";UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:str];if (nil == cell) {cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:str]autorelease];}Student *stu = [self.arr objectAtIndex:indexPath.row];cell.textLabel.text = stu.name;cell.detailTextLabel.text = stu.number;cell.imageView.image = stu.image;return cell;
}// tableView的delegate方法
// 点击某一个cell
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{FirstViewController *first = [[FirstViewController alloc]init];[self.navigationController pushViewController:first animated:YES];Student *stu = [self.arr objectAtIndex:indexPath.row];first.str = stu.name;first.str1 = stu.number;first.img1 = stu.image;first.index = indexPath.row;first.delegate = self;[first release];}// 修改方法
- (void)changeName:(NSString *)name Number:(NSString *)number index:(NSInteger)index
{Student *stu = [self.arr objectAtIndex:index];stu.name = name;stu.number = number;[[self.view.subviews firstObject]reloadData];}- (void)didReceiveMemoryWarning
{[super didReceiveMemoryWarning];// Dispose of any resources that can be recreated.
}
#import <UIKit/UIKit.h>
#import "Student.h"
@interface MainViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>@property (nonatomic, retain)NSMutableArray *arr;@property (nonatomic, retain)UITableView *table;/// 修改方法
- (void)changeName:(NSString *)name Number:(NSString *)number index:(NSInteger)index;
/// 添加方法
- (void)insertStu:(Student *)stu;@end
#import "FirstViewController.h"
#import "MainViewController.h"
@interface FirstViewController ()<UITextFieldDelegate>@end@implementation FirstViewController- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];if (self) {// Custom initialization}return self;
}- (void)viewDidLoad
{[super viewDidLoad];self.view.backgroundColor = [UIColor magentaColor];UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(30, 100, 100, 110)];image.image = self.img1;image.backgroundColor = [UIColor whiteColor];[self.view addSubview:image];[image release];UITextField *textName = [[UITextField alloc]initWithFrame:CGRectMake(200, 100, 100, 30)];textName.tag = 1000;textName.borderStyle = UITextBorderStyleRoundedRect;textName.text = self.str;textName.backgroundColor = [UIColor whiteColor];[self.view addSubview:textName];[textName release];UILabel *laber = [[UILabel alloc]initWithFrame:CGRectMake(150, 100, 40, 30)];laber.text = @"姓名";laber.backgroundColor = [UIColor clearColor];[self.view addSubview:laber];UITextField *textNum = [[UITextField alloc]initWithFrame:CGRectMake(200, 180, 100, 30)];textNum.tag = 2000;textNum.borderStyle = UITextBorderStyleRoundedRect;textNum.delegate = self;textNum.text = self.str1;textNum.backgroundColor = [UIColor whiteColor];[self.view addSubview:textNum];[textNum release];UILabel *laber1 = [[UILabel alloc]initWithFrame:CGRectMake(150, 180, 40, 30)];laber1.text = @"电话";laber1.backgroundColor = [UIColor clearColor];[self.view addSubview:laber1];[laber release];UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];button.frame = CGRectMake(130, 300, 60, 30);[button setTitle:@"保存" forState:UIControlStateNormal];button.backgroundColor = [UIColor whiteColor];[self.view addSubview:button];[button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];// Do any additional setup after loading the view.
}// 键盘收回
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{[textField resignFirstResponder];return YES;
}// 点击修改后保存实现方法
- (void)buttonClick:(UIButton *)button
{UITextField *name = (UITextField *)[self.view viewWithTag:1000];UITextField *number = (UITextField *)[self.view viewWithTag:2000];[self.delegate changeName:name.text Number:number.text index:self.index];}
<pre name="code" class="objc">#import <UIKit/UIKit.h>
#import "Student.h"// 指定协议
@protocol PassValueDelegate <NSObject>// 制定方法
- (void)changeName:(NSString *)name Number:(NSString *)number index:(NSInteger)index;@end@interface FirstViewController : UIViewController
@property (nonatomic, retain)Student *stu;@property (nonatomic, assign)NSInteger index;
@property (nonatomic, copy)NSString *str;
@property (nonatomic, copy)NSString *str1;
@property (nonatomic, copy)UIImage *img1;@property (nonatomic, assign)id<PassValueDelegate>delegate;@end
#import "SecondViewController.h"
#import "Student.h"
@interface SecondViewController ()<UITextFieldDelegate>@end@implementation SecondViewController- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];if (self) {// Custom initializationself.stu = [[Student alloc] init];[_stu release];}return self;
}- (void)dealloc
{[_stu release];[super dealloc];
}- (void)viewDidLoad
{[super viewDidLoad];self.view.backgroundColor = [UIColor magentaColor];UITextField *textImg = [[UITextField alloc]initWithFrame:CGRectMake(30, 100, 100, 110)];textImg.tag = 3000;textImg.delegate = self;textImg.borderStyle = UITextBorderStyleRoundedRect;textImg.backgroundColor = [UIColor whiteColor];[self.view addSubview:textImg];[textImg release];UITextField *textName = [[UITextField alloc]initWithFrame:CGRectMake(200, 100, 100, 30)];textName.tag = 1000;textName.delegate = self;textName.borderStyle = UITextBorderStyleRoundedRect;textName.backgroundColor = [UIColor whiteColor];[self.view addSubview:textName];[textName release];UILabel *laber = [[UILabel alloc]initWithFrame:CGRectMake(150, 100, 40, 30)];laber.text = @"姓名";laber.backgroundColor = [UIColor clearColor];[self.view addSubview:laber];UITextField *textNum = [[UITextField alloc]initWithFrame:CGRectMake(200, 180, 100, 30)];textNum.tag = 2000;textNum.delegate = self;textNum.borderStyle = UITextBorderStyleRoundedRect;textNum.backgroundColor = [UIColor whiteColor];[self.view addSubview:textNum];[textNum release];UILabel *laber1 = [[UILabel alloc]initWithFrame:CGRectMake(150, 180, 40, 30)];laber1.text = @"电话";laber1.backgroundColor = [UIColor clearColor];[self.view addSubview:laber1];[laber release];UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];button.frame = CGRectMake(130, 300, 60, 30);[button setTitle:@"保存" forState:UIControlStateNormal];button.backgroundColor = [UIColor whiteColor];[self.view addSubview:button];[button addTarget:self action:@selector(insertStu:) forControlEvents:UIControlEventTouchUpInside];// Do any additional setup after loading the view.
}- (void)insertStu:(Student *)stu;
{UITextField *name = (UITextField *)[self.view viewWithTag:1000];UITextField *number = (UITextField *)[self.view viewWithTag:2000];UITextField *img = (UITextField *)[self.view viewWithTag:3000];self.stu.name = name.text;self.stu.number = number.text;self.stu.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@.jpg",img.text]];[self.delegate insertStu:self.stu];[self.navigationController popToRootViewControllerAnimated:YES];
}// 键盘收回
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{[textField resignFirstResponder];return YES;
}
#import <UIKit/UIKit.h>
#import "Student.h"
@protocol InsertViewDelegate <NSObject>- (void)insertStu:(Student *)stu;@end@interface SecondViewController : UIViewController@property (nonatomic, retain)Student *stu;@property (nonatomic, assign)id<InsertViewDelegate>delegate;@end
#import "Student.h"@implementation Student- (id)initwithName:(NSString *)name Number:(NSString *)number Image:(UIImage *)image
{self = [super init];if ( self) {_name = name;_number = number;_image = image;}return self;
}- (void)dealloc
{[_name release];[_number release];[_image release];[super dealloc];
}@end
#import <Foundation/Foundation.h>@interface Student : NSObject@property (nonatomic, retain)NSString *name;
@property (nonatomic, retain)NSString *number;
@property (nonatomic, retain)UIImage *image;- (id)initwithName:(UIImage *)name Number:(NSString *)number Image:(NSString *)image;@end

能够实现添加,修改及删除的通讯录相关推荐

  1. 给jqGrid数据行添加修改和删除操作链接

    我这里用的不是jqGrid的自带的编辑和删除操作,我已经把分页导航栏下的编辑,删除,搜索都取消掉了,就是这句$("#list1").navGrid("#pager1&qu ...

  2. html表格中添加修改和删除链接,jQuery实现为table表格动态添加或删除tr功能示例...

    本文实例讲述了jQuery实现为table表格动态添加或删除tr功能.分享给大家供大家参考,具体如下: HTML页面元素如下: 订单合同号 捆包号 品名 规格 材质 重量 业务需求是,从后台获取到订单 ...

  3. Entity Framework Code First添加修改及删除单独实体

    对于一个单独实体的通常操作有3种:添加新的实体.修改实体以及删除实体. 1.添加新的实体 Entity Framework Code First添加新的实体通过调用DbSet.Add()方法来实现. ...

  4. DNS添加/修改/查询/删除A记录

    #查询DNS可用类 Get-WmiObject -Namespace root\MicrosoftDNS -List #查询所有资源记录 $mydns = [WMIClass]"ROOT\M ...

  5. oracle 添加,修改,删除表字段以及备注和重命名表,重命名列

    语法 添加字段:alter table tablename add (column datatype [default value][null/not null],-.); 修改字段:alter ta ...

  6. ShopEx customSchema 定制可以根据客户的需求对网站进行相应功能的添加修改或者删除

    站内锚文本制作 1.修改config.php,在文件末尾加入以下内容 define('CUSTOM_CORE_DIR',BASE_DIR . '/custom'); 2.增加custom文件夹(与co ...

  7. 《Python编程从入门到实践》记录之第3章 列表简介总结——列表添加修改和删除元素(思维导图)

  8. Swift - 添加、修改、删除通讯录联系人

    使用AddressBook.framework框架,我们除了可以很方便的获取通信录里的联系人.同时,还能对通讯录进行新增.修改.删除联系人操作. (注意:这些操作同查询一样,首先需要发起授权请求) 1 ...

  9. 实现具备添加、查看、修改以及删除联系人信息功能的手机通讯录。

    实现具备添加.查看.修改以及删除联系人信息功能的手机通讯录. print("--------------手机通讯录-------------") print("--- 1 ...

最新文章

  1. CVPR 2020 论文大盘点-全景分割与视频目标分割篇
  2. 7-5 表格输出 (C语言)
  3. mysql 5.5 5.6差异,MySQL5.5和MySQL5.6授权区别
  4. 都在建议你不要直接使用 @Async 注解,为什么?
  5. 2进程之间的关系:进程组,会话,守护进程
  6. 计算机应用基础在线作业南开,2017南开计算机应用基础在线作业满分的答案.doc...
  7. .NET Core开发实战(第21课:中间件:掌控请求处理过程的关键)--学习笔记(下)...
  8. X-UA-Compatible,IE8 兼容模式
  9. 外推主要发布平台(JM)
  10. debian 安装 php,Ubuntu/Debian上安装Nginx+php环境详细教程
  11. 重磅,企业实施大数据的路径
  12. 关于atollic truestudio for stm32
  13. jQuery获取iframe中页面的高度
  14. 3ds Max 材质贴图
  15. paper—基于 GCN 的安卓恶意软件检测模型
  16. Problem:跳房子
  17. 怎么将file转换为html,怎么将PDF文件转换为HTML?分享四种实用方法!
  18. 国内外电子合同运用的差异
  19. 雷电模拟器一键宏实现循环点击
  20. java项目如何发送邮件

热门文章

  1. 单片机学习笔记——微机基础知识
  2. 无人机巡检,风力发电机组表面缺陷检测数据集(YOLO标签)
  3. 计算机改显存会有啥影响,显卡显存越大越好吗?显存对电脑速度的影响有哪些?...
  4. 北京大学光华管理学院开通CnOpenData试用
  5. 2022年终总结——从打工到创业的转折
  6. google earth的网页版
  7. 3D激光SLAM:LeGO-LOAM论文解读---激光雷达里程计与建图
  8. std::tuple、std::tie(可用于结构体大小比较)、std::pair用法
  9. Java 程序员开发常用的工具
  10. 深度学习之NN(Neural Network)