Swift 闭包传值 反向传值

RT


A界面 接收B界面返回的时候的值


A界面


        let vc = CZHourPicker()
        
        vc.backClosure = {(backStr: String) -> Void in
            self.durationBtn.setTitle(backStr, for: UIControlState.normal)
            self.durationBtnT.setTitle(backStr, for: UIControlState.normal)
        }
        
        self.present(vc, animated: true, completion: nil)


B界面

//定义闭包类型(特定的函数类型函数类型)
typealias InputClosureType = (String) -> Void


  //接收上个页面传过来的闭包块
    var backClosure: InputClosureType?




       self.backClosure!(resultStr)
       self.dismiss(animated: true, completion: nil)




你可能感兴趣的:(Swift)