OC中声明block;
typedef void(^RefreshHintLabelBlock)(NSString *hintString);
@interface SecondViewController : UIViewController
@property (nonatomic, copy) RefreshHintLabelBlock hintBlock;
@end
OC中实现block
-(BOOL)navigationShouldPopOnBackButton{
if (_hintBlock) {
NSlog(@"输出了")
}
return YES;
}
swift中实现
func pushAction(_ sender: AnyObject) {
let secondVC = SecondViewController.init()
secondVC.secondDelegate = self;
//这里
secondVC.hintBlock = {(t:String?)in
self.hintLabel.text = "secondView textView.text = " + t!
}
self.navigationController?.pushViewController(secondVC, animated: true)
}
网友评论