Swift 4在视图之间传递数据

时间:2018-07-26 10:19:38

标签: swift request parameter-passing

我无法将请求从func传递到下一个视图。我想将我的请求从VC1传递到VC2,以将其发送到WkWebView。

VC1包含以下代码:

var request = URLRequest(url: payURL!)
request.httpMethod = "POST"
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")

let p = String(format: "TotalAmount=%@&Signature=%@&OrderID=%@&Version=%@&PurchaseTime=%@&TerminalID=%@&MerchantID=%@&Currency=%@&locale=%@&PurchaseDesc=%@",
                param["TotalAmount"]!    as! CVarArg,
                param["Signature"]!      as! CVarArg,
                param["OrderID"]!        as! CVarArg,
                param["Version"]!        as! CVarArg,
                param["PurchaseTime"]!   as! CVarArg,
                param["TerminalID"]!     as! CVarArg,
                param["MerchantID"]!     as! CVarArg,
                param["Currency"]!       as! CVarArg,
                param["locale"]!         as! CVarArg,
                param["PurchaseDesc"]!   as! CVarArg)

request.httpBody = p.data(using: String.Encoding.utf8, allowLossyConversion: true)
let payController = kMainStoryboard.instantiateViewController(withIdentifier: "EVPayControllerViewController") as! EVPayControllerViewController
payController.request = request
navigationController?.present(payController, animated: true, completion: nil)

VC2

class EVPayControllerViewController: UIViewController, WKNavigationDelegate, UIWebViewDelegate {

    var request: URLRequest?
    let wkWebView = WKWebView()
    let webView = UIWebView()



    override func viewDidLoad() {
        super.viewDidLoad()

        print(request?.httpBody)  //nil
    }
}

0 个答案:

没有答案