1)view中写法
1、申请 (PdViewController)
typedef void(^btnTouchClick) (NSInteger tag); //返回 传值(可以多个)
2、block属性
@property (nonatomic,copy) btnTouchClick touchBlock;
3、按钮点击事件后,二级页面传值
- (void)btnDown:(UIButton *)btn
{
if (self.touchBlock) {
self.touchBlock(arc4random()%100);
}
}
4、首页调用并实现 (MainViewController)
pdView.touchBlock = ^(NSInteger tag) {
NSLog(@"tag...........%ld",tag);
};
2)viewcontroller中写法,界面反向传值
1、传值界面,b界面
.himport <UIKit/UIKit.h>
import "ViewController.h"
typedef void(^returnBlock)(NSString *str);
@interface BBViewController : UIViewController<MMDelegate>
@property (nonatomic, copy) returnBlock block;
@end
.m
-
(void)btnClick
{
ViewController *vc = [[ViewController alloc] init];
vc.delegate = self;
[vc changeStr:@"21345678"];if (self.block) {
self.block(@"b -->block");
}[self dismissViewControllerAnimated:YES completion:nil];
}
2.展示界面
包含BBViewController的头文件,实现即可- (void)btnClick
{
BBViewController *bb = [[BBViewController alloc] init];
bb.block = ^ (NSString *str) {
NSLog(@"%@",str);
};
[self presentViewController:bb animated:YES completion:nil];
} - (void)btnClick
网友评论