#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
@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