传递文本字段值Swift 4

时间:2018-05-16 01:40:41

标签: ios swift

我有三个viewcontrollers注册用户,  我想将我的文本字段值从按钮传递到另一个viewcontroller的按钮,以便完成注册。我尝试了所有我知道的但没有运气

这是来自firstViewController的按钮

@IBAction func nextButtonTapped(_ sender: Any) {

   let parameters:Parameters=[
       "name":nameTextfield.text!,
       "phone":phoneTextfield.text!
   ]
 }

这是第三个ViewController的按钮操作

    @IBAction func registerButtonTapped(_ sender: Any) {

    //Sending http post request

    Alamofire.request(URL_USER_REGISTER, method: .post, parameters: parameters).responseJSON {
        response in
        //printing response
        print(response)

        //getting the json value from the server
        if let result = response.result.value {

            //converting it as NSDictionary
            let jsonData = result as! NSDictionary

            //displaying the message in label
            //self.labelMessage.text = jsonData.value(forKey: "message") as! String?
        }
    } 

1 个答案:

答案 0 :(得分:0)

尝试以下步骤

1.使用静态变量创建模型

import Foundation

class Model
{
    static var textA:String?
    static var textB:String?
    static var textC:String?
}

2。单击按钮

时,将值分配给模型
Model.textA = textField.text!

3。从第三个ViewController访问值

 let parameters:Parameters=[
       "name":Model.textA!,
       "phone":Model.textA!
   ]