iOS-代理托付的使用
#import "Rigester_ViewController.h"
#import "Rigester_ViewController.h"
@interface Rigester_ViewController ()
@end
@implementation Rigester_ViewController
*
正向传值能够用属性
反向传值代理Block
代理:又叫托付
自己不能办得事托付给别人去干
UIAlertView,UITextField 都使用了代理
写代理的步骤:
// 须要代理,托付的人
1.声明代理里面的协议方法(@protocol)
2.声明协议的属性
3.什么时候须要触发这个代理方法
4.通过协议的属性调用代理方法(托付)
// 代理者。被托付的人须要做的事
5.导入协议
6.在初始化有代理方法的对象的地方
挂上代理(代理者响应代理)
7.写上代理方法
等待被运行
*/
- (void)viewDidLoad {
[super viewDidLoad];
self.title = _titleName;
UIButton *rigesterButton = [UIButton buttonWithType:UIButtonTypeCustom];
rigesterButton.frame = CGRectMake(150, 550, 100, 50);
[self.view addSubview:rigesterButton];
rigesterButton.backgroundColor = [UIColor orangeColor];
rigesterButton.showsTouchWhenHighlighted = YES;
rigesterButton.layer.cornerRadius = 10;
[rigesterButton setTitle:@"注冊" forState:UIControlStateNormal];
[rigesterButton addTarget:self action:@selector(toRigester) forControlEvents:UIControlEventTouchUpInside ];
}
//什么时候触发这个代理方法
- (void)toRigester
{
[self.navigationController popViewControllerAnimated:YES];
// 4.通过协议的属性调用代理的方法
[self.delegate toLoginWithName:@"JZQ"];
}
- (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
@interface Rigester_ViewController ()
@end
@implementation Rigester_ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.title = _titleName;
UIButton *rigesterButton = [UIButton buttonWithType:UIButtonTypeCustom];
rigesterButton.frame = CGRectMake(150, 550, 100, 50);
[self.view addSubview:rigesterButton];
rigesterButton.backgroundColor = [UIColor orangeColor];
rigesterButton.showsTouchWhenHighlighted = YES;
rigesterButton.layer.cornerRadius = 10;
[rigesterButton setTitle:@"注冊" forState:UIControlStateNormal];
[rigesterButton addTarget:self action:@selector(toRigester) forControlEvents:UIControlEventTouchUpInside ];
}
//什么时候触发这个代理方法
- (void)toRigester
{
[self.navigationController popViewControllerAnimated:YES];
// 4.通过协议的属性调用代理的方法
[self.delegate toLoginWithName:@"JZQ"];
}
- (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
iOS-代理托付的使用的更多相关文章
- QF——iOS代理模式
iOS的代理模式: A要完成某个功能,它可以自己完成,但有时出于一些原因,不方便自己完成.这时A可以委托B来帮其完成此功能,即由B代理完成.但是这个功能不是让B随随便便任其完成.此时,会有一个协议文件 ...
- iOS代理模式
iOS代理模式的简单理解:当一个对象无法直接获取到另一个对象的指针,又希望对那个变量进行一些操作时,可以使用代理模式. 代理主要由三部分组成: (1)协议:用来指定代理双方可以做什么,必须做什么. ( ...
- 你真的了解iOS代理设计模式吗?
在项目中我们经常会用到代理的设计模式,这是iOS中一种消息传递的方式,也可以通过这种方式来传递一些参数.这篇文章会涵盖代理的使用技巧和原理,以及代理的内存管理等方面的知识.我会通过这些方面的知识,带大 ...
- iOS 代理反向传值
在上篇博客 iOS代理协议 中,侧重解析了委托代理协议的概念等,本文将侧重于它们在开发中的应用. 假如我们有一个需求如下:界面A上面有一个button.一个label.从界面A跳转到界面B,在界面B的 ...
- 【转】你真的了解iOS代理设计模式吗?
转自:http://www.cocoachina.com/ios/20160317/15696.html 在项目中我们经常会用到代理的设计模式,这是iOS中一种消息传递的方式,也可以通过这种方式来传递 ...
- IOS 代理的简单实现
原文 http://www.cnblogs.com/lovekarri/archive/2012/03/04/2379197.html 昨天做了一个demo,用到了简单代理. delegate是ios ...
- iOS代理模式(delegate)的使用
前言: 代理模式是iOS中非常重要的一个模式,iOS SDK中的系统控件几乎都用到了代理模式.代理模式用来处理事件监听.参数传递功能. 协议创建(Protocol): 可手打如下代码,或者在代码块里面 ...
- iOS 代理 重定向消息 forwardInvocation
今天简单研究一下iOS的重定向消息forwardInvocation: 首先看看Invocation类: @interface NSInvocation : NSObject { @private _ ...
- iOS 代理设计模式
在项目中经常会用到代理的设计模式,这是iOS中一种消息传递的方式,也可以通过这种方式传递一些参数. 在项目中,刚开始我是用一些代理来传递参数的,但是慢慢觉得代理的代码比较block多,所以就更多的使用 ...
- fiddler 进行Android/IOS代理配置抓包
1.准备:Android+IOS设备 下载:fiddler抓包工具,不是最新版的链接: 链接:https://pan.baidu.com/s/1BaBfu2H4xgpsh1wmkfC8aQ ...
随机推荐
- [MySQL] lock知识梳理
MySQL Lock机制 INDEX: MySQL事务隔离级别 MVCC MySQL Lock类型 MySQL MDL CONTENT: 1. MySQL事务隔离级别 Read Uncommit RU ...
- react native windows create bundle folder
生成bundle 文件 命令 react-native bundle --platform android --dev false --entry-file index.js --bundle-out ...
- encodeURI 解码 编码
var uriStr = "http://www.baidu.com?name=张三&num=001 zs"; var uriec = encodeURI(uriStr); ...
- Add and Search Word - Data structure design - LeetCode
Design a data structure that supports the following two operations: void addWord(word) bool search(w ...
- Windows Server 2008 IE 无法调整安全级别
开始”/“程序”/“管理工具”/“服务器管理器”命令,在弹出的服务器管理器窗口中,找到“安全信息”设置项,单击其中的“配置IE ESC”选项,打开如下图所示的IE增强安全配置窗口.
- asp.net怎样解决高并发问题
队列+多线程+couchbase缓存 ,解决高并发问题. using System; using System.Collections.Generic; using System.Linq; usin ...
- iOS 5的文件存储策略应对
苹果在iOS 5系统时,对app的文件存储提出了新的要求.从它的guildline来看,是推荐开发者尽量把app生成的文件放在Caches目录下的.原文如下: Only user-generated ...
- dedecms让channelartlist标签支持currentstyle属性方
把dedecms中用channelartlist当导航的站很普遍,但是有的站需要用到当前页中导航样,就是随着不同的页面,导航样式也随着变化. 首先打开include\taglib\channelart ...
- ElasticSearch搜索term和terms的区别
今天同事使用ES查询印地语的文章.发现查询报错,查询语句和错误信息如下: 查询语句:{ "query":{ "bool":{ ...
- Linux学习之十-Linux系统时间
Linux系统时间 1.date命令用于查看以及修改Linux系统的时间,关于date命令的详细帮助文档如下 [root@localhost ~]# date --help Usage: date [ ...