1.VCOne
.m
#import "ViewController.h"
#import "SecondViewController.h"
@interface ViewController ()
@property (nonatomic,strong) UILabel *label;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
_label = [[UILabel alloc] initWithFrame:CGRectMake(50, 100, 100, 50)];
_label.font = [UIFont systemFontOfSize:15];
_label.textColor = [UIColor redColor];
[self.view addSubview:_label];
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
SecondViewController *vc = [SecondViewController new];
vc.sendData = ^(NSString *message){
_label.text = message;
};
[self presentViewController:vc animated:YES completion:nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
2.VCTwo
.h
#import <UIKit/UIKit.h>
@interface SecondViewController : UIViewController
@property(nonatomic,strong) void(^sendData)(NSString *str);
@end
.m
#import "SecondViewController.h"
@interface SecondViewController ()
@end
@implementation SecondViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor yellowColor];
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
if (self.sendData) {
self.sendData(@"666666");
}
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
就是这么简单,打完收工