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


评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值