【发布时间】:2017-12-02 15:06:05
【问题描述】:
我是 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
}
}
}
}
现在发生的情况是,我第一次点击第二个 tableview 的第一个 viewdidload 行时会出现,因为 db.collection 是异步的,结果我必须按下回然后点击同一行才能查看来自的数据第一击。
【问题讨论】:
-
你必须在主线程上重新加载第二个控制器表视图。
-
我应该添加 func 重新加载数据并重新加载表还是应该在 viewDidload 中执行?我不确定如何执行此操作。
标签: ios swift firebase google-cloud-firestore