将第二个文件中的textField中的值传到第一个文件的lable中
第一步:重命名 typedef void (^passValueBlock) (NSString *);?
@Property SenondViewController: UIViewController
@Property (nonatomic,strong)passValueBlock passvalueblock;
[email protected]
@interface SenondViewController ()
@Property (nonatomic,strong) UITextField *textfield;
@end
第二步执行block
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
self.passValueBlock (self.textfield.text);(这句是重点)
[self dismissViewControllerAnimated:YES completion:nil];
}?
? 第三步在第一个文件的.m中接收传过来的值
#import "RootViewController.h"
#import "CustomViewController.h"
@interfaceRootViewController ()
@property(nonatomic,strong)UILabel *label;
@end
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
SenondViewController? *senondVC=[SenondViewController new];
// 展开block
senondVC?.passValueBlock=^(NSString *text){
self.lable.text=text;
}?;
[selfshowDetailViewController: senondVC sender:nil];
}?
这只是传值的一种方法
除此之外还有属性传值,代理传值,代理传值等方法