无法将VC中的Firebase文档ID发送到VC

时间:2019-09-09 01:53:31

标签: swift firebase google-cloud-firestore

我正在对firebase运行查询,我能够获取documentID,但无法将documentID发送到另一个VC。我得到他所查询的所有内容,没有任何问题。我不确定我缺少什么。任何建议,不胜感激。

第一个VC

@IBAction func getDataTapped(_ sender: Any) {
    SVProgressHUD.show()

    if HOSP != (hospNameTxt.text!) {
        ptListQuery = ptListCollectionRef?.whereField("hosp", isEqualTo: (hospNameTxt.text!))
    }

    ptListQuery?.getDocuments { (snapshot, error) in
        if let err = error {
            debugPrint("error getting data: \(err)")
        } else {
            guard let snap = snapshot else { return }
            for document in snap.documents {
                let data = document.data()
                let ptName = data[PTNAME] as? String ?? ""
                let assignedMd = data[ASSIGNEDMD] as? String ?? ""
                let officeMd = data[OFFICEMD] as? String ?? ""
                let assignedDate = data[ASSIGNEDDATE] as? String ?? ""
                let seeNoSee = data[SEENOSEE] as? String ?? ""
                let room = data[ROOM] as? String ?? ""
                let app = data[APP] as? String ?? ""
                let documentId = document.documentID
                let username = data[USERNAME] as? String ?? ""
                let userId = data[USER_ID] as? String ?? ""

                let newPtList = PTList(ptName: ptName,
                                       assignedMd: assignedMd,
                                       officeMd: officeMd,
                                       assignedDate: assignedDate,
                                       seeNoSee: seeNoSee,
                                       room: room,
                                       app: app, documentId: documentId,
                                       username: username, userId: userId
                )
                self.ptListInCell.append(newPtList)
                print("docID", documentId) //this shows the documentID in the console
                print(document.data()) //this shows everything in the array but the document ID
            }
        }

        self.performSegue(withIdentifier: "goToResults", sender: self)
    }
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "goToResults" {
        let vc = segue.destination as! ResultsdataVC
        vc.ptListFromCell = ptListInCell
        SVProgressHUD.dismiss()
    }
}

第二个VC

class ResultsdataVC: UIViewController, UITableViewDataSource, UITableViewDelegate, PatListCellDelegate {

    @IBOutlet weak var resultsTableView: UITableView!
    @IBOutlet weak var patientFilter: UISegmentedControl!

    var ptListFromCell = [PTList]()
    var ptDatasToPass = [PTData]()
    var selectedFilter = FilterCategory.hosp.rawValue
    var patientListener: ListenerRegistration!
    var patientCollectionRef: CollectionReference!
    //segmentedControl
    var dataFilter = 0
    var tableDataSee : [String] = ["Yes"]
    var tableDataNoSee : [String] = ["No"]


    override func viewDidLoad() {
        super.viewDidLoad()

        resultsTableView.delegate = self
        resultsTableView.dataSource = self
        resultsTableView.rowHeight = 110

    }

这是PTList模型:

class PTList {

    private(set) var ptName: String!
    private(set) var assignedMd: String!
    private(set) var officeMd: String!
    private(set) var assignedDate: String!
    private(set) var seeNoSee: String!
    private(set) var room: String!
    private(set) var app: String!
    private(set) var documentId: String!
    private(set) var username: String!
    private(set) var userId: String!

    init(ptName: String, assignedMd: String, officeMd: String, assignedDate: String, seeNoSee: String, room: String, app: String, documentId: String, username: String, userId: String) {

        self.ptName = ptName
        self.assignedMd = assignedMd
        self.officeMd = officeMd
        self.assignedDate = assignedDate
        self.seeNoSee = seeNoSee
        self.room = room
        self.app = app
        self.documentId = documentId
        self.username = username
        self.userId = userId
    }
}

这是我的数据库结构

enter image description here

0 个答案:

没有答案