私は素早くfirebaseサービスに新しいです 私はデータベースとしてfire storeデータベースを使用しています。すべてのデータを読み込んで素敵なテーブルビューに入れる最初のテーブルビューを持っています。私のテーブルビューのすべてのドキュメントにはサブコレクションがあります。ユーザーが行を押すと、サブコレクションを持つ2番目のテーブルビューを開きます。セグを使用してデータを転送
これは私のセグエコードの準備です:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let indexPath = tableViewDishes.indexPathForSelectedRow {
db.collection("Restaurants").document("Applebees").collection("Menu").document(sections[indexPath.section].sectionName!).collection("Dishes").document(sections[indexPath.section].listofDishes![indexPath.row].DishName).collection("Options").getDocuments { (querySnapshot, error) in
if error != nil {print(error)}
else {
for document in querySnapshot!.documents {
//adding all the data to an array called myOption
}
}
}
let selectedDishTableViewController = segue.destination as! SelectedDishViewController
selectedDishTableViewController.myOption = self.myOption
selectedDishTableViewController.dish = self.sections[indexPath.section].listofDishes?[indexPath.row]
selectedDishTableViewController.sectionName = sections[indexPath.section].sectionName!
self.myOption.removeAll()
}
}
問題は私のコードたらdb.collectionラインに到達myOptionのみ、空の配列であるとするとき、それはループのために、すぐ後にジャンプしていることですそれは戻って、私の配列にオブジェクトを追加します。
最初に行を押すと、2番目のテーブルビューが空になり、戻ってもう一度押すと必要な情報が表示されます。
すべての 'db.collection(...)'行が非同期呼び出しを行っています。これは実際にクロージャーに入ります(ここでは 'querySnapshot!.documents'の' for document 'を書きました)。クエリを実行した後にのみ 'performSegue()'を呼び出します。 – Larme