做货运代理网站,wordpress建设论坛,wordpress 虎嗅网,网址提交入口大全一、实现功能说明 #xff08;1#xff09;点击注销按钮#xff0c;弹出一个对话框#xff0c;点击确定后移除当前栈顶的控制器#xff0c;返回开始界面#xff0c;点击取消#xff0c;不做任何操作。 注意#xff1a;注销按钮的单击事件已经进行了连线。实现-(void)ac…一、实现功能说明 1点击注销按钮弹出一个对话框点击确定后移除当前栈顶的控制器返回开始界面点击取消不做任何操作。 注意注销按钮的单击事件已经进行了连线。实现-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex需要遵守UIActionSheetDelegate协议。 1 //注销按钮2 - (IBAction)logoutBtn:(id)sender {3 4 UIActionSheet *sheet [[UIActionSheet alloc]initWithTitle:确定要注销? delegate:self cancelButtonTitle:取消 destructiveButtonTitle:确定 otherButtonTitles: nil];5 6 [sheet showInView:self.view];7 }8 9 #pragma mark-代理方法
10 -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
11 {
12 if (buttonIndex!0)return;
13 //移除栈顶的控制器
14 [self.navigationController popViewControllerAnimated:YES];
15 } 2当两个文本框的状态发生改变时通知添加按钮变为可用状态。 知识点通知注册监听 1 - (void)viewDidLoad2 {3 [super viewDidLoad];4 5 //1.获得通知中心6 NSNotificationCenter *center[NSNotificationCenter defaultCenter];7 //2.注册监听8 [center addObserver:self selector:selector(textChange) name:UITextFieldTextDidChangeNotification object:self.nameFeild];9 [center addObserver:self selector:selector(textChange) name:UITextFieldTextDidChangeNotification object:self.phoneFeild];
10 }
11
12
13
14 //当文本框内容改变的时候通知self调用该方法
15 -(void)textChange
16 {
17 //判断如果两个文本框的内容都改变有值的时候添加按钮变成可交互的
18 self.addBtn.enabled(self.nameFeild.text.length0self.phoneFeild.text.length0);
19 NSLog(通知调用的事件);
20 }
21
22 //临终遗言
23 -(void)dealloc
24 {
25 [[NSNotificationCenter defaultCenter] removeObserver:self];
26 } 3数据的逆传使用代理 YYContatcsViewController.m文件 1 //2 // YYContatcsViewController.m3 // 01-私人通讯录登录页面搭建4 //5 // Created by apple on 14-6-8.6 // Copyright (c) 2014年 itcase. All rights reserved.7 //8 9 #import YYContatcsViewController.h10 #import YYAddViewController.h11 #import YYInfoModel.h12 13 //遵守协议14 interface YYContatcsViewController ()UIActionSheetDelegate,YYAddViewControllerDelegate15 property (strong, nonatomic) IBOutlet UITableView *tableview;16 17 //数组用来保存用户添加的数据18 property(nonatomic,strong)NSMutableArray *array;19 20 - (IBAction)logoutBtn:(id)sender;21 22 end23 24 implementation YYContatcsViewController25 26 27 - (void)viewDidLoad28 {29 [super viewDidLoad];30 }31 32 //注销按钮33 - (IBAction)logoutBtn:(id)sender {34 35 UIActionSheet *sheet [[UIActionSheet alloc]initWithTitle:确定要注销? delegate:self cancelButtonTitle:取消 destructiveButtonTitle:确定 otherButtonTitles: nil];36 37 [sheet showInView:self.view];38 }39 40 #pragma mark-代理方法41 -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex42 {43 if (buttonIndex!0)return;44 //移除栈顶的控制器45 [self.navigationController popViewControllerAnimated:YES];46 }47 48 49 -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender50 {51 UIViewController *csegue.destinationViewController;52 YYAddViewController *addc(YYAddViewController *)c;53 addc.delegateself;54 55 }56 57 #pragma mark-YYAddViewControllerDelegate58 -(void)addViewControllerDidAddBtn:(YYAddViewController *)addViewController contatc:(YYInfoModel *)contatc59 {60 //1.把数组保存到数组中61 // [self.Info addObject:contatc];62 // //2.刷新表格63 // NSLog(%,contatc);64 // NSLog(%,self.Info);65 // [self.tableview reloadData];66 NSLog(%,%,contatc.name,contatc.phone);67 [self.array addObject:contatc];68 [self.tableview reloadData];69 70 }71 72 -(NSMutableArray *)array73 {74 if (_arrayNil) {75 _array[NSMutableArray array];76 }77 return _array;78 }79 #pragma mark-tableview的数据源80 //一共有多少行81 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section82 {83 // return self.Info.count;84 return self.array.count;85 }86 //每组每行的cell87 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath88 {89 static NSString *identifierinfo;90 //先去缓存中取。如果缓存中没有那么就到storyboard中去查找91 UITableViewCell *cell[tableView dequeueReusableCellWithIdentifier:identifier];92 //在storyboard中设置cell的标识符为info93 94 //设置cell的数据95 // 96 // UITableViewCell *cell[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Nil];97 98 YYInfoModel *infoself.array[indexPath.row];99 cell.textLabel.textinfo.name;
100 cell.detailTextLabel.textinfo.phone;
101
102
103 //返回cell
104 return cell;
105 }
106 end YYAddViewController.h文件 1 //2 // YYAddViewController.h3 // 01-私人通讯录登录页面搭建4 //5 // Created by 孔医己 on 14-6-8.6 // Copyright (c) 2014年 itcase. All rights reserved.7 //8 9 #import UIKit/UIKit.h
10 class YYAddViewController, YYInfoModel;
11 //自定义一个协议让上一个控制器YYContatcsViewController成为当前控制器的代理
12
13 //protocol YYAddViewControllerDelegate NSObject
14 //
15 ////协议方法
16 //-(void)addViewControllerDidAddBtn:(YYAddViewController *)addViewController contatc:(YYInfoModel *)contatc;
17
18 protocol YYAddViewControllerDelegate NSObject
19
20 //- (void)editViewControllerDidAddBtn:(NJEditViewController *)editViewController name:(NSString *)name number:(NSString *)phoneNumber;
21
22 - (void)addViewControllerDidAddBtn:(YYAddViewController *)editViewController contatc:(YYInfoModel *)contatc;
23
24 end
25
26 interface YYAddViewController : UIViewController
27
28 //新增一个代理属性
29 property(nonatomic,strong)idYYAddViewControllerDelegate delegate;
30
31 end YYAddViewController.m文件 1 //2 // YYAddViewController.m3 // 01-私人通讯录登录页面搭建4 //5 // Created by 孔医己 on 14-6-8.6 // Copyright (c) 2014年 itcase. All rights reserved.7 //8 9 #import YYAddViewController.h
10 #import YYInfoModel.h
11
12 interface YYAddViewController ()
13 //姓名输入框
14 property (weak, nonatomic) IBOutlet UITextField *nameFeild;
15 //电话号码输入框
16 property (weak, nonatomic) IBOutlet UITextField *phoneFeild;
17 //添加按钮
18 property (weak, nonatomic) IBOutlet UIButton *addBtn;
19
20 //添加按钮的点击事件
21 - (IBAction)addBtnOnclick:(id)sender;
22
23 end
24
25 implementation YYAddViewController
26
27
28 #pragma mark- 监听是否添加
29 - (void)viewDidLoad
30 {
31 [super viewDidLoad];
32
33 //1.获得通知中心
34 NSNotificationCenter *center[NSNotificationCenter defaultCenter];
35 //2.注册监听
36 [center addObserver:self selector:selector(textChange) name:UITextFieldTextDidChangeNotification object:self.nameFeild];
37 [center addObserver:self selector:selector(textChange) name:UITextFieldTextDidChangeNotification object:self.phoneFeild];
38 }
39
40
41
42 //当文本框内容改变的时候通知self调用该方法
43 -(void)textChange
44 {
45 //判断如果两个文本框的内容都改变有值的时候添加按钮变成可交互的
46 self.addBtn.enabled(self.nameFeild.text.length0self.phoneFeild.text.length0);
47 NSLog(通知调用的事件);
48 }
49
50 //临终遗言
51 -(void)dealloc
52 {
53 [[NSNotificationCenter defaultCenter] removeObserver:self];
54 }
55
56
57 - (void)viewDidAppear:(BOOL)animated
58 {
59 // 3.主动召唤出键盘
60 [self.nameFeild becomeFirstResponder];
61 // [self.nameField resignFirstResponder];
62 }
63
64
65 - (IBAction)addBtnOnclick:(id)sender {
66
67 //点击添加按钮后把数据保存到模型数组中
68 //跳转
69 [self.navigationController popViewControllerAnimated:YES];
70
71 //1.把当前界面文本框中的信息保存到模型中
72 YYInfoModel *info[[YYInfoModel alloc]init];
73 info.nameself.nameFeild.text;
74 info.phoneself.phoneFeild.text;
75
76 //2.数据逆传把当前控制器view的数据传递到上一个控制器的view中
77 //使用代理自定义一个代理并使用代理传递数据
78 //如果代理方法存在就通知代理调用该方法传递数据
79 if ([self.delegate respondsToSelector:selector(addViewControllerDidAddBtn:contatc:)]) {
80 NSLog(sadafaf);
81 [self.delegate addViewControllerDidAddBtn:self contatc:info];
82 }
83
84 NSLog(dddd);
85 }
86 end 二、效果 注销的弹窗效果 添加信息 信息添加后返回到联系人列表界面 转载于:https://www.cnblogs.com/dondre/p/4094633.html