block传值
import “MainViewController.h”
import “SecondViewController.h”
@interface MainViewController ()
import “SecondViewController.h”
import “MainViewController.h”
@interface SecondViewController ()
@property(nonatomic,retain)UIButton *button;
@property(nonatomic,retain)UITextField *textField;
@end
@implementation SecondViewController
(void)dealloc
{
[_textField release];
[_button release];
[super dealloc];
}(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.self.button=[UIButton buttonWithType:(UIButtonTypeSystem)];
self.button.frame=CGRectMake(100, 200, 175, 50);
[self.view addSubview:self.button];
[self.button setTitle:@”返回” forState:UIControlStateNormal];
self.button.layer.borderWidth=1;
self.button.layer.cornerRadius=10;
self.button.titleLabel.font=[UIFont systemFontOfSize:20];
[self.button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];self.textField=[[UITextField alloc] initWithFrame:CGRectMake(100, 0, 175, 50)];
[self.view addSubview:self.textField];
[self.textField release];
self.textField.placeholder=@”输入人名”;
self.textField.layer.borderWidth=1;
}
-(void)click:(UIButton *)button{
[self.navigationController popToRootViewControllerAnimated:YES];
self.block(self.textField.text);
}