質問編集履歴
3
改善
title
CHANGED
File without changes
|
body
CHANGED
@@ -3,6 +3,9 @@
|
|
3
3
|
|
4
4
|
そこで、テーブルセルを削除した時にFirebaseにある本の情報も削除したいのですがエラーが出てしまいます。
|
5
5
|
|
6
|
+
恐らく、 削除メソッド のDatabasに関する記述の仕方が違うのではないかと思いますが、どのように記述したら良いかわかりません。
|
7
|
+
|
8
|
+
|
6
9
|
どなたかご教授しただければ幸いです。
|
7
10
|
よろしくお願いいたします。
|
8
11
|
|
@@ -28,7 +31,7 @@
|
|
28
31
|
tableView.deleteRows(at: [indexPath as IndexPath], with: .fade)
|
29
32
|
}
|
30
33
|
}
|
31
|
-
|
34
|
+
// 削除メソッド
|
32
35
|
func delete(deleteIndexPath indexPath: IndexPath) {
|
33
36
|
|
34
37
|
Database.database().reference().child("users").child(userID).child(contentsArray[indexPath.row].key).removeValue()
|
2
内容を詳しくした
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,13 +1,21 @@
|
|
1
|
+
swiftで読書管理アプリを作成しております。
|
1
|
-
|
2
|
+
Firebaseでは、usersにそれぞれのユーザーが本の情報を持っています。
|
2
3
|
|
4
|
+
そこで、テーブルセルを削除した時にFirebaseにある本の情報も削除したいのですがエラーが出てしまいます。
|
5
|
+
|
6
|
+
どなたかご教授しただければ幸いです。
|
7
|
+
よろしくお願いいたします。
|
8
|
+
|
3
9
|
## 削除したい項目
|
4
10
|

|
5
11
|
|
6
12
|
|
7
13
|
## エラー内容
|
14
|
+
```
|
15
|
+
*** Terminating app due to uncaught exception 'InvalidPathValidation', reason: '(child:) Must be a non-empty string and not contain '.' '#' '$' '[' or ']''
|
16
|
+
```
|
8
17
|
|
9
18
|
|
10
|
-
|
11
19
|
```swift
|
12
20
|
|
13
21
|
// データを削除
|
1
正しい質問内容に変更
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
テ
|
1
|
+
【Swift】テーブルセル削除時にFIrebaseも削除する方法について
|
body
CHANGED
@@ -1,1 +1,31 @@
|
|
1
|
+
テーブルセルを削除した時にFirebaseの内容も削除したいのですがエラーが出てしまいます。
|
2
|
+
|
3
|
+
## 削除したい項目
|
4
|
+

|
5
|
+
|
6
|
+
|
7
|
+
## エラー内容
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
```swift
|
12
|
+
|
13
|
+
// データを削除
|
14
|
+
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
|
15
|
+
//デリートボタンを追加
|
16
|
+
if editingStyle == .delete {
|
17
|
+
//選択されたCellのNSIndexPathを渡し、データをFirebase上から削除するためのメソッド
|
18
|
+
self.delete(deleteIndexPath: indexPath)
|
19
|
+
//TableView上から削除
|
20
|
+
tableView.deleteRows(at: [indexPath as IndexPath], with: .fade)
|
21
|
+
}
|
22
|
+
}
|
23
|
+
|
1
|
-
|
24
|
+
func delete(deleteIndexPath indexPath: IndexPath) {
|
25
|
+
|
26
|
+
Database.database().reference().child("users").child(userID).child(contentsArray[indexPath.row].key).removeValue()
|
27
|
+
contentsArray.remove(at: indexPath.row)
|
28
|
+
|
29
|
+
}
|
30
|
+
}
|
31
|
+
```
|