代理传值

来源:互联网 发布:铅笔袋淘宝 编辑:程序博客网 时间:2024/06/11 05:56

1、在ViewController.h里

#import "ViewController.h"#import "DelegateViewController.h"@interface ViewController ()<meDelegateViewController>@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];    UIButton *btn=[[UIButton alloc]init];    btn.frame = CGRectMake(100, 200, 120, 50);    btn.backgroundColor=[UIColor blueColor];    [btn setTitle:@"代理传值" forState:UIControlStateNormal];    [btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];    [self.view addSubview:btn];}-(void)btnClick{    DelegateViewController * delegateVC = [[DelegateViewController alloc] init];    delegateVC.delegate = self;    [self.navigationController pushViewController:delegateVC animated:YES];}#pragma 代理方法-(void)delegateClick:(NSString *)meStr{    NSLog(@"我是获值方,此方法是在传值方触发 == %@",meStr);}- (void)didReceiveMemoryWarning {    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}@end
0 0
原创粉丝点击