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

iOS-代理托付的使用

时间:2017-05-12 20:30:41      阅读:274      评论:0      收藏:0      [点我收藏+]

标签:top   pass   ack   size   range   send   ott   ima   20px   

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

标签:top   pass   ack   size   range   send   ott   ima   20px   

原文地址:http://www.cnblogs.com/lxjshuju/p/6846800.html

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