block的目的就是传值,今天写个最简单的block,希望看官看后有所启发.
界面2:
界面2.h
#import <Foundation/Foundation.h>
typedef void (^succeccBlock)(NSDictionary *responseDic);
@interface block : NSObject
- (void)success:(succeccBlock)successBlock;
@end
界面2.m
#import "block.h"
@implementation block
- (void)success:(succeccBlock)successBlock{
NSDictionary *resultDic = @{@"key":@"123"};
successBlock(resultDic);
}
@end
接下来就是接收数据了
界面1.m
- (void)viewDidLoad {
[super viewDidLoad];
block *block1 = [[block alloc] init];
[block1 success:^(NSDictionary *responseDic) {
NSString *value = responseDic[@"key"];
NSLog(@"%@",value);
}];
// Do any additional setup after loading the view, typically from a nib.
}
打印结果