swift 调用 OC中的block

2018-05-02  本文已影响0人  择一城终老_蜗牛

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)  
}  
上一篇 下一篇

猜你喜欢

热点阅读