質問編集履歴
2
ソースコードを割愛したので、その対処の文章
test
CHANGED
File without changes
|
test
CHANGED
@@ -49,6 +49,8 @@
|
|
49
49
|
|
50
50
|
|
51
51
|
### 該当のソースコード
|
52
|
+
|
53
|
+
コードが長くて、最後まで書くと、10000字を超えてしまいますので、「この部分はどうなっている?」的な質問があれば、教えてください!!!
|
52
54
|
|
53
55
|
```swift
|
54
56
|
|
1
tableViewの「編集モード」を実装した際の、コードです!!
test
CHANGED
File without changes
|
test
CHANGED
@@ -50,4 +50,122 @@
|
|
50
50
|
|
51
51
|
### 該当のソースコード
|
52
52
|
|
53
|
+
```swift
|
54
|
+
|
55
|
+
//MARK:Cellの編集(削除)==========================================
|
56
|
+
|
57
|
+
//MARK:①Cellの編集を許可するか
|
58
|
+
|
59
|
+
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
|
60
|
+
|
61
|
+
return true
|
62
|
+
|
63
|
+
}
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
//MARK:Cellの編集の種類
|
70
|
+
|
71
|
+
//MARK:①で指定したCellは、通常状態で、スワイプによる削除が可能になるので、その挙動を明示化
|
72
|
+
|
73
|
+
func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle {
|
74
|
+
|
75
|
+
//MARK:編集状態の時
|
76
|
+
|
77
|
+
if tableView.isEditing{
|
78
|
+
|
79
|
+
return UITableViewCell.EditingStyle.delete
|
80
|
+
|
81
|
+
//MARK:通常状態の時(スワイプアクション)
|
82
|
+
|
83
|
+
}else{
|
84
|
+
|
85
|
+
return UITableViewCell.EditingStyle.delete
|
86
|
+
|
87
|
+
}
|
88
|
+
|
89
|
+
}
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
//MARK:スワイプ時表示されるボタンのタイトル
|
96
|
+
|
97
|
+
func tableView(_ tableView: UITableView, titleForDeleteConfirmationButtonForRowAt indexPath: IndexPath) -> String? {
|
98
|
+
|
99
|
+
return "削除"
|
100
|
+
|
101
|
+
}
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
//MARK:Cellの編集の種類毎の処理
|
110
|
+
|
111
|
+
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
|
112
|
+
|
113
|
+
//MARK:削除ボタンを押した時の処理
|
114
|
+
|
115
|
+
if editingStyle == .delete{
|
116
|
+
|
117
|
+
//MARK:tableViewに反映する配列(配列から特定の順番の要素の消去)
|
118
|
+
|
119
|
+
//MARK:Cellの削除
|
120
|
+
|
121
|
+
//MARK:おそらくここでFirebaseの値を更新するのではないか???
|
122
|
+
|
123
|
+
}
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
//MARK:Cellの編集(並び替え)==========================================
|
140
|
+
|
141
|
+
//MARK:Cellの並び替えを許可するかどうか
|
142
|
+
|
143
|
+
func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
|
144
|
+
|
145
|
+
if indexPath.section == 1{
|
146
|
+
|
147
|
+
return true
|
148
|
+
|
149
|
+
}else{
|
150
|
+
|
53
|
-
|
151
|
+
return false
|
152
|
+
|
153
|
+
}
|
154
|
+
|
155
|
+
}
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
//MARK:並び替えのつまみから指を離したタイミングで呼ばれるメソッド
|
160
|
+
|
161
|
+
func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
|
162
|
+
|
163
|
+
//MARK:配列の中の順番を変更
|
164
|
+
|
165
|
+
//MARK:移動先の順番を変更
|
166
|
+
|
167
|
+
//MARK:このメソッド内ではないが、Firebaseの処理は必要
|
168
|
+
|
169
|
+
}
|
170
|
+
|
171
|
+
```
|