将String数据从一个ViewController移到另一个

时间:2019-02-14 14:25:02

标签: swift firebase firebase-realtime-database swift4

至此: 这是我在Firebase上的数据库

enter image description here

我有一个代码,当我使用唯一的电子邮件登录时,它会给我来自数据库的firstNamelastname。这是代码:

func retrieveInfo () {

    let reference = Database.database().reference().child("User_Informations").queryOrdered(byChild: "email")
    reference.queryEqual(toValue: emailTextfield.text!).observeSingleEvent(of: .childAdded) { (snapshot) in

        let dictionary = snapshot.value as! [String : String]
        let firstName = dictionary["firstName"]
        let lastName = dictionary["lastName"]


    }


}

retriveInfo可以成功检索名字和姓氏,但是问题是我想将名字和姓氏传递给另一个视图控制器,以便在包含(名字和姓氏)的文本字段上显示它”看到图片”:

enter image description here

这是目标视图控制器的代码:

class HomeScreenViewController: UIViewController {

@IBOutlet var firstNameLabel: UILabel!
@IBOutlet var lastNameLabel: UILabel!
@IBOutlet var diverRankLabel: UILabel!
@IBOutlet var personalImage: UIImageView!

var firstNameChanged = Information().firstName
var lastNameChanged = Information().lastName
var diverRankChanged = ""

let databaseref = Database.database().reference()

override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.

}

information类:

class Information {

//Objects
var firstName : String = ""
var lastName : String = ""
var email : String = ""
var diverRank : String = ""


}

希望一切都清楚,在此先感谢:)

0 个答案:

没有答案