从保存在 firebase swift 中的 UIPicker 视图中检索密钥 ID

问题描述

我正在尝试解决,如何将 UIPicker ID 保存在 firebase 中。

我的目标是将部门 ID 与导师 ID 相关联,所以我的部门名称保存到 firbase 作为 nood

Firebase Tree

应用屏幕:

app screen

我对 UIPckier 视图的观察者:

    @objc func ObserveDepartmentFromDatabase () {
    
    
    APIs.Department_APIs.OberveDepartment { (dep) in
        self.DepartmentContiner.append(dep)
    }

}

注册新的导师用户

    @IBAction func SignUp(_ sender: Any) {
    Auth.auth().createuser(withEmail: Email.text!,password: Password.text!) { (user,error) in
        if error != nil{
            print(error?.localizedDescription as Any)
                            return
            } else {
            print("user auth successfully")

            guard let userID = Auth.auth().currentUser?.uid else {
            return
            }
            // storge Image
            let storge : StorageReference!
                storge = Storage.storage().reference(withPath: "gs://uquaac-f7b71.appspot.com ").child("Profile_Images").child(userID)
            if let profileImage = self.userSelectimageToStorage,let ProfileIMG = profileImage.jpegData(compressionQuality: 0.1){
            storge.putData(ProfileIMG,Metadata: nil) { (MetaData,error) in
                if error != nil {
                    print(error?.localizedDescription as Any)
                    return
                }else{
                    storge.downloadURL { (url: URL?,error:  Error?) in
                        let profileURL = url?.absoluteString
                        
                      
        // save DataBase

        let ref : DatabaseReference!
        ref = Database.database().reference()
        let userRef = ref.child("StudentAndTutor")
       

        let newUserREF = userRef.child(userID)
        newUserREF.setValue(["name" : self.Name.text,"email" : self.Email.text,"phoneNumber" : self.PhoneNumber.text,"department" : self.Department.text,"password" : self.Password.text,"profilImage" : profileURL,"userType" : self.userType.text]) { (error,ref) in
            if error != nil {
                print(error?.localizedDescription)
            }
            let linkeDepartmentWithTutor = Database.database().reference().child("linkeDepartmentWithTutorID")
            
            linkeDepartmentWithTutor.child(self.Department.text!).child(userID).setValue(true) { (error,ref) in
                if error != nil {
                                   print(error?.localizedDescription)
                               }
            }
        }
        

  
        let storyboard = UIStoryboard(name: "Main",bundle: nil)
          let vc = storyboard.instantiateViewController(withIdentifier: "TabBar")
          vc.modalPresentationStyle = .overFullScreen
        self.present(vc,animated: true)
    }
    
                    }
                }
            }
          
            
        }
    }

}

数据库显示如下

红线是指 UI 部门键,但在“LinkeDepartmentWithTutorID”中它不显示 ID 它只显示字符串所以我需要知道如何观察当前部门 ID 并将其链接到导师 ID

database tree

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)