我是iOS和Firebase的新手。

我有一张表格视图,可以显示我的Firestore中的文档,
每个文档都有一个子集合,我想在行中获取它,并在第二个tableView中显示新数据

现在我正在使用:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    switch segue.identifier {

    case "showOptions"?:
    let selectedDishTableViewController = segue.destination as! SelectedDishViewController
    if let indexPath = tableViewDishes.indexPathForSelectedRow {
        brain.loadOptions(dish: brain.listOfDishes[indexPath.row])
        selectedDishTableViewController.dish = brain.listOfDishes[indexPath.row]
        selectedDishTableViewController.myOption = brain.myOption
        brain.myOption.removeAll()
        }
        default: break
    }
}


这是我的大脑功能:

func loadOptions(dish:Dish) {

        db.collection("Restaurants").document("Limon").collection("Menu").document((self.sectionName!)).collection("Dishes").document(dish.DishName).collection("Options").getDocuments { [weak self](querySnapshot, error) in
            if error != nil {print(error)}
            else {
                for document in querySnapshot!.documents {
                    // appending the data to my Array that will be presented in the next tableView
                }
            }
        }

}


现在发生的是,因为db.collection异步,所以我第一次单击该行时第二个tableview的first viewdidload就会出现,结果我必须按回去,然后单击同一行才能看到第一次命中的数据。

最佳答案

所以我设法解决了未来的Google员工问题,
我为db.collection添加了完成处理程序,并在第二个tableView的ViewDidApear中使用了tableview.reloaddata()

关于ios - 从Firestore提取数据时准备进行安全检查,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47609246/

10-11 00:19
查看更多