在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)

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-23
  • 2022-12-23
  • 2022-01-14
  • 2022-12-23
  • 2022-12-23
  • 2021-11-29
猜你喜欢
  • 2022-12-23
  • 2022-03-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案