简易通讯录
来源:互联网 发布:剑网三淘宝买金 编辑:程序博客网 时间:2024/06/08 16:26
#import "MainViewController.h"#import "SecondViewController.h"#import "ThirdViewController.h"@interface MainViewController ()<UITableViewDataSource, UITableViewDelegate, SecondViewControllerDelegate, ThirdViewControllerDelegate>@property(nonatomic, retain)UITableView *tableView;@property(nonatomic, retain)NSMutableArray *arr;@property(nonatomic, retain)NSMutableDictionary *dic;@property(nonatomic, assign)NSInteger index;@property(nonatomic, assign)NSInteger num;@end@implementation MainViewController- (void)dealloc{ [_dic release]; [_arr release]; [_tableView release]; [super dealloc];}- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.navigationController.navigationBar.translucent = NO; 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.delegate = self; self.tableView.dataSource = self;// 设置导航栏标题 self.navigationItem.title = @"首页"; self.navigationItem.rightBarButtonItem =[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"1.png"] style:UIBarButtonItemStylePlain target:self action:@selector(click:)]; NSString *path = [[NSBundle mainBundle] pathForResource:@"StudentArr" ofType:@"plist"]; self.arr = [NSMutableArray array]; self.arr = [NSMutableArray arrayWithContentsOfFile:path];}- (void)sendMessage:(NSMutableDictionary *)dic { [self.arr addObject:dic];}- (void)click:(UIButton *)button{ ThirdViewController *thirdVC = [[ThirdViewController alloc] init]; [self.navigationController pushViewController:thirdVC animated:YES]; [thirdVC release]; thirdVC.delegate = self; }- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.arr.count;}- (void)changeValue:(NSMutableDictionary *)dic index:(NSInteger)index{ [self.arr replaceObjectAtIndex:index withObject:dic]; [self.tableView reloadData];}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *reuse = @"reuse"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse]; if (!cell) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuse] autorelease]; } self.dic = self.arr[indexPath.row]; cell.textLabel.text = self.dic[@"name"]; cell.detailTextLabel.text = self.dic[@"phone"]; NSString *picName = [NSString stringWithFormat:@"%ld.jpg", indexPath.row + 1]; cell.imageView.image = [UIImage imageNamed:picName]; return cell;}- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ SecondViewController *secondVC = [[SecondViewController alloc] init]; [self.navigationController pushViewController:secondVC animated:YES]; [secondVC release]; secondVC.dic = self.arr[indexPath.row]; secondVC.delegate = self; secondVC.count = indexPath.row;}
<pre name="code" class="objc">#import <UIKit/UIKit.h>@protocol SecondViewControllerDelegate <NSObject>- (void)changeValue:(NSMutableDictionary *)dic index:(NSInteger)index;@end@interface SecondViewController : UIViewController@property(nonatomic, assign)id<SecondViewControllerDelegate>delegate;@property(nonatomic, retain)NSMutableDictionary *dic;@property(nonatomic, assign)NSInteger count;@end
#import "SecondViewController.h"#define WIDTH self.view.frame.size.width#define HEIGHT self.view.frame.size.height@interface SecondViewController ()<UIAlertViewDelegate>@property(nonatomic, retain)UITextField *name;@property(nonatomic, retain)UITextField *sex;@property(nonatomic, retain)UITextField *hobby;@property(nonatomic, retain)UITextField *phone;@property(nonatomic, retain)UIButton *done;@property(nonatomic, assign)BOOL isOn;@end@implementation SecondViewController- (void)dealloc{ [_done release]; [_phone release]; [_hobby release]; [_sex release]; [_name release]; [_dic release]; [super dealloc];}- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.isOn = YES; self.navigationItem.title = @"修改"; self.view.backgroundColor = [UIColor yellowColor]; self.name = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 40)]; self.name.layer.borderWidth = 1; self.name.layer.cornerRadius = 10; [self.view addSubview:self.name]; [self.name setText:self.dic[@"name"]]; self.name.textAlignment = NSTextAlignmentCenter; [_name release]; self.sex = [[UITextField alloc] initWithFrame:CGRectMake(0, 40, WIDTH, 40)]; self.sex.layer.borderWidth = 1; self.sex.layer.cornerRadius = 10; [self.view addSubview:self.sex]; [self.sex setText:self.dic[@"sex"]]; self.sex.textAlignment = NSTextAlignmentCenter; [_sex release]; self.hobby = [[UITextField alloc] initWithFrame:CGRectMake(0, 80, WIDTH, 40)]; self.hobby.layer.borderWidth = 1; self.hobby.layer.cornerRadius = 10; [self.view addSubview:self.hobby]; [self.hobby setText:self.dic[@"hobby"]]; self.hobby.textAlignment = NSTextAlignmentCenter; [_hobby release]; self.phone = [[UITextField alloc] initWithFrame:CGRectMake(0, 120, WIDTH, 40)]; self.phone.layer.borderWidth = 1; self.phone.layer.cornerRadius = 10; [self.view addSubview:self.phone]; [self.phone setText:self.dic[@"phone"]]; self.phone.textAlignment = NSTextAlignmentCenter; [_phone release]; self.done = [UIButton buttonWithType:UIButtonTypeSystem]; self.done.layer.borderWidth = 1; self.done.layer.cornerRadius = 10; self.done.frame = CGRectMake(150, 360, 60, 40); [self.done setTitle:@"完成" forState:UIControlStateNormal]; [self.view addSubview:self.done]; [self.done addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];}- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ [self.name resignFirstResponder]; [self.sex resignFirstResponder]; [self.phone resignFirstResponder]; [self.hobby resignFirstResponder];}- (void)click{ UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"确认后就更改,请慎重" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil]; alertView.delegate = self; [alertView show]; [alertView release];}- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ if (buttonIndex) { [self.dic setValue:self.name.text forKey:@"name"]; [self.dic setValue:self.sex.text forKey:@"sex"]; [self.dic setValue:self.hobby.text forKey:@"hobby"]; [self.dic setValue:self.phone.text forKey:@"phone"]; [self.delegate changeValue:self.dic index:self.count]; [self.navigationController popViewControllerAnimated:YES]; } if (buttonIndex == 0){ [self.name setText:self.dic[@"name"]]; NSLog(@"%@", self.dic[@"name"]); [self.sex setText:self.dic[@"sex"]]; [self.hobby setText:self.dic[@"hobby"]]; [self.phone setText:self.dic[@"phone"]]; }}
#import <UIKit/UIKit.h>@protocol ThirdViewControllerDelegate <NSObject>- (void)sendMessage:(NSMutableDictionary *)dic;@end@interface ThirdViewController : UIViewController@property(nonatomic, assign)id<ThirdViewControllerDelegate>delegate;@end
#import "ThirdViewController.h"#define WIDTH self.view.frame.size.width@interface ThirdViewController ()@property(nonatomic, retain)UITextField *name;@property(nonatomic, retain)UITextField *sex;@property(nonatomic, retain)UITextField *hobby;@property(nonatomic, retain)UITextField *phone;@property(nonatomic, retain)UIButton *done;@property(nonatomic ,retain)NSMutableDictionary *dic;@end@implementation ThirdViewController- (void)dealloc{ [_dic release]; [_done release]; [_phone release]; [_hobby release]; [_sex release]; [_name release]; [super dealloc];}- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.navigationItem.title = @"新建联系人"; self.view.backgroundColor = [UIColor yellowColor]; self.name = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 40)]; self.name.layer.borderWidth = 1; self.name.layer.cornerRadius = 10; [self.view addSubview:self.name]; self.name.placeholder = @"请输入姓名"; self.name.textAlignment = NSTextAlignmentCenter; [_name release]; self.sex = [[UITextField alloc] initWithFrame:CGRectMake(0, 40, WIDTH, 40)]; self.sex.layer.borderWidth = 1; self.sex.layer.cornerRadius = 10; [self.view addSubview:self.sex]; self.sex.textAlignment = NSTextAlignmentCenter; self.sex.placeholder = @"请输入性别"; [_sex release]; self.hobby = [[UITextField alloc] initWithFrame:CGRectMake(0, 80, WIDTH, 40)]; self.hobby.layer.borderWidth = 1; self.hobby.layer.cornerRadius = 10; [self.view addSubview:self.hobby]; self.hobby.textAlignment = NSTextAlignmentCenter; self.hobby.placeholder = @"请输入爱好"; [_hobby release]; self.phone = [[UITextField alloc] initWithFrame:CGRectMake(0, 120, WIDTH, 40)]; self.phone.layer.borderWidth = 1; self.phone.layer.cornerRadius = 10; [self.view addSubview:self.phone]; self.phone.textAlignment = NSTextAlignmentCenter; self.phone.placeholder = @"请输入电话"; [_phone release]; self.done = [UIButton buttonWithType:UIButtonTypeSystem]; self.done.layer.borderWidth = 1; self.done.layer.cornerRadius = 10; self.done.frame = CGRectMake(150, 360, 60, 40); [self.done setTitle:@"完成" forState:UIControlStateNormal]; [self.view addSubview:self.done]; [self.done addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside]; }- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ [self.name resignFirstResponder]; [self.sex resignFirstResponder]; [self.hobby resignFirstResponder]; [self.phone resignFirstResponder]; }- (void)click{ self.dic = [NSMutableDictionary dictionary]; [self.dic setValue:self.name.text forKey:@"name"]; [self.dic setValue:self.sex.text forKey:@"sex"]; [self.dic setValue:self.hobby.text forKey:@"hobby"]; [self.dic setValue:self.phone.text forKey:@"phone"]; [self.delegate sendMessage:self.dic]; [self.navigationController popToRootViewControllerAnimated:YES];}
0 0
- 简易通讯录
- 简易通讯录
- 简易通讯录
- 简易通讯录
- 简易通讯录
- 简易通讯录
- 简易通讯录
- 简易通讯录
- 简易通讯录--首页
- 简易通讯录代码
- Android简易通讯录
- android 简易通讯录查询
- 简易android通讯录
- 简易QQ通讯录
- 简易QQ通讯录
- OC简易通讯录
- 【C语言】 简易通讯录
- 实现一个简易通讯录
- A. Toy Cars
- Logistic回归
- 阿拉卡拉卡韩国
- 获取屏幕宽高和密度
- hdoj 48119 Mosaic (二维线段树 单点更新)
- 简易通讯录
- C++设计模式——原型模式
- 括号配对
- Top 3000+ Python Modules
- 博客网页制作
- 【codevs1068】乌龟棋noip10年TG----第二个A掉的钻石题
- hpuoj1693 YY难题【DFS】
- [leetcode 235]Lowest Common Ancestor of a Binary Search Tree
- opennms 图表配置(Charts)