美文网首页
swift 调用 OC中的block

swift 调用 OC中的block

作者: 择一城终老_蜗牛 | 来源:发表于2018-05-02 16:16 被阅读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)  
}  

相关文章

网友评论

      本文标题:swift 调用 OC中的block

      本文链接:https://www.haomeiwen.com/subject/llyklftx.html