传递视图控制器之间的电子邮件值

时间:2018-04-13 10:38:37

标签: ios swift

我想传递价值"电子邮件"当我按下按钮时,从一个VC到另一个VC。所以我想用firebase和swift 4创建一个注册,首先一个视图控制器问我电子邮件,输入电子邮件后,我点击下一步,另一个视图控制器会询问我的密码,然后点击注册。如何保存第一个ViewController的电子邮件并将其传递给第二个ViewController?然后将第一个vc的电子邮件和第二个vc的密码发送到firebase?对不起我的英语不好。在实践中,它必须像instagram注册一样工作。

import Foundation
import Firebase
import FirebaseAuth
import UITextField_Shake

internal class SignUpSegue0 : UIViewController {




@IBOutlet weak var labelwrongpass: UILabel!
@IBOutlet weak var Emailsign: UITextField!

func isValidEmail(testStr:String) -> Bool {

    print("validate emilId: \(testStr)")
    let emailRegEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}"
    let emailTest = NSPredicate(format:"SELF MATCHES %@", emailRegEx)
    let result = emailTest.evaluate(with: testStr)
    return result

}


@IBAction func Nextsign1(_ sender: UIButton) {

    guard let email = Emailsign.text else { return }

    if Emailsign.text == "" {
        self.labelwrongpass.text = "Please enter your email"
        self.Emailsign.shake(10,withDelta: 5.0)

     } else {

        Auth.auth().fetchProviders(forEmail: email, completion: {
            (providers, error) in

       if error != nil {
            print("Email disponibile")
            self.labelwrongpass.text = "Email inserita correttamente"
            self.labelwrongpass.textColor = UIColor.green

        func prepare(for segue: UIStoryboardSegue, sender: Any?)
        {
            if segue.destination is SignUpSegue1
            {
                let vc = segue.destination as? SignUpSegue1
                vc?.email = ""

            }
        }


        } else if providers != nil {
            print("L'email inserita è già esistente")
            self.labelwrongpass.text = nil
            self.labelwrongpass.text = "L'email inserita è già esistente"
            self.Emailsign.shake(10,withDelta: 5.0)


            }
    })

     }

     }
       }

1 个答案:

答案 0 :(得分:0)

您可以在目标控制器中创建一个var:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="home">
  <div class="head_section"></div>
  <div class="sticky-menu"></div>
</div>

在您的控制器中覆盖PrepareForSegue,例如:

class DestinationViewController: UIViewController {

    var variableToShare : String?

    //the rest of the class methods....