[Swift 开发] 使用闭包传值(typealias)

在Swift中使用闭包来实现两个界面的传值

 

例如:有A类和B类.

B类

//声明闭包
typealias valueBlock = (Float)->()
var returnPrice: valueBlock?
 
 
//调用该闭包
self.returnPrice?(price)

A类

let sb = UIStoryboard(name:"Main", bundle: nil)
        
let vc = sb.instantiateViewControllerWithIdentifier("keypadViewVC") as! keypadViewVC
        
//B类的回调
vc.returnPrice = {price in self.gratuityBtn.setTitle(String(format: "%.2f", price), forState:UIControlState.Normal)}
        
self.presentViewController(vc, animated: true, completion: nil)

 

posted @ 2018-09-03 18:06  心泪无恒  阅读(1293)  评论(0编辑  收藏  举报