swift 简单的闭包传值

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

在返回值页面:
声明:

 typealias getTitleAndID = (String,String) -> Void
    var biBao:(getTitleAndID)!

跳页返回时候

self.biBao(self.needTitle!,self.needID!)
            self.popVC()

接受返回值的页面:(其实也是点击跳页的方法中)

  func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        if indexPath.row == 2 {
            let SB = UIStoryboard.init(name: "Main", bundle: Bundle.main)
            let VC = SB.instantiateViewController(withIdentifier: "AddressDetailVC") as! AddressDetailVC
            VC.biBao = {(title,ID) in
                print(title,"--------------",ID)
                self.needTitle = title
                self.needID = ID
                self.tableView.reloadRows(at: [indexPath], with: .none)
            }
            self.navigationController?.pushViewController(VC, animated: true)
        }
    }
上一篇 下一篇

猜你喜欢

热点阅读