//定义block,带参数
在TextViewController.h文件里:
typedef void (^TextViewBlock)(NSString *text, NSString *target);
@interface TextViewController : BaseViewController
//属性
@property (nonatomic, strong) NSString *targetCode;
@property (nonatomic, strong) NSString *placeHolder;
//block
@property (nonatomic, copy) TextViewBlock doneBlock;
@end
在MainViewController.m文件里:
TextViewController *textVC = (TextViewController *)pushVC;
//.....................省略。。。。。
__weak id weakSelf = self;
textVC.doneBlock = ^(NSString *text, NSString *targetLang) {
MainViewController *strongSelf = weakSelf;
[strongSelf.navigationController popViewControllerAnimated:YES];
。。。。。。。。。。。。。。。。
};
- (void)dealloc
{
self.doneBlock = nil;
}
if(self.doneBlock) {
self.doneBlock(textView.text, self.targetCode);
self.doneBlock = nil;
}
//定义block,不带参数
在BusiViewController.h文件里:
typedef void (^BusFinishBlock)();
@interface BusViewController : BaseViewController
@property (nonatomic, copy) BusFinishBlock selBlock;
@end
在mainViewController.m文件里:
bsVC.selBlock = ^() {
[UIView animateWithDuration:0.2
animations:^{
。。。。。。。。。。。。。。。。。。。
}
completion:^(BOOL finished) {
MainViewController *strongSelf = weakSelf;
。。。。。。。。。。。。。。。。。。。
};
};
在BusViewController.m文件里:
- (void) dealloc
{
self.selBlock = nil;
}
另一块的代码:
if(self.selectedBlock) {
self.selectedBlock();
}