码迷,mamicode.com
首页 > 移动开发 > 详细

iOS-代理委托的使用

时间:2015-07-29 09:07:08      阅读:466      评论:0      收藏:0      [点我收藏+]

标签:

#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-代理委托的使用

标签:

原文地址:http://blog.csdn.net/jzq_sir/article/details/47121529

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!