質問編集履歴
6
追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -341,3 +341,53 @@
|
|
341
341
|
}
|
342
342
|
|
343
343
|
```
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
解決方法備忘録
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
```swift
|
352
|
+
|
353
|
+
// generateCell
|
354
|
+
|
355
|
+
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
356
|
+
|
357
|
+
let cell = typeOfCatsTableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
let typeOfCatStr = typesOfCatsArray[indexPath.row]
|
362
|
+
|
363
|
+
|
364
|
+
|
365
|
+
// typeOfCatsTableView.reloadData()時に、ここで選択済み配列に入っている猫の種類をselectする
|
366
|
+
|
367
|
+
print("selectedCatsArray:",selectedCatsArray)
|
368
|
+
|
369
|
+
if selectedCatsArray.contains(typeOfCatStr) == true {
|
370
|
+
|
371
|
+
typeOfCatsTableView.selectRow(at: indexPath, animated: false, scrollPosition: .none)
|
372
|
+
|
373
|
+
} else {
|
374
|
+
|
375
|
+
typeOfCatsTableView.deselectRow(at: indexPath, animated: false)
|
376
|
+
|
377
|
+
}
|
378
|
+
|
379
|
+
|
380
|
+
|
381
|
+
cell.textLabel!.text = typeOfCatStr
|
382
|
+
|
383
|
+
|
384
|
+
|
385
|
+
return cell
|
386
|
+
|
387
|
+
}
|
388
|
+
|
389
|
+
|
390
|
+
|
391
|
+
コード
|
392
|
+
|
393
|
+
```
|
5
コード追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -225,3 +225,119 @@
|
|
225
225
|
|
226
226
|
|
227
227
|
![イメージ説明](bfaecea3d2facff54435b2bdc34a4f09.gif)
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
```swift
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
//簡素化したコード。これ以外は、StoryboardにTableView・Cellを配置してCellのidentifierを設定、TableViewをOutlet接続しただけです。
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
import UIKit
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
var typesOfCatsArray: [String] = ["ジバニャン", "ワルニャン", "フユニャン", "イヌニャン", "サルニャン", "イチゴニャン"]
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
@IBOutlet weak var typeOfCatsTableView: UITableView!
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
//MARK: - LifeCycle -
|
258
|
+
|
259
|
+
override func viewDidLoad() {
|
260
|
+
|
261
|
+
super.viewDidLoad()
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
// tableViewの編集を可能にする
|
266
|
+
|
267
|
+
typeOfCatsTableView.isEditing = true
|
268
|
+
|
269
|
+
//typeOfCatsTableView.allowsSelectionDuringEditing = true
|
270
|
+
|
271
|
+
typeOfCatsTableView.allowsMultipleSelectionDuringEditing = true
|
272
|
+
|
273
|
+
}
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
override func didReceiveMemoryWarning() {
|
278
|
+
|
279
|
+
super.didReceiveMemoryWarning()
|
280
|
+
|
281
|
+
}
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
//MARK: - UITableViewDataSource -
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
// numberOfCell
|
290
|
+
|
291
|
+
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
292
|
+
|
293
|
+
return typesOfCatsArray.count
|
294
|
+
|
295
|
+
}
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
// generateCell
|
300
|
+
|
301
|
+
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
302
|
+
|
303
|
+
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
cell.textLabel!.text = typesOfCatsArray[indexPath.row]
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
return cell
|
312
|
+
|
313
|
+
}
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
// sortable
|
318
|
+
|
319
|
+
func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
|
320
|
+
|
321
|
+
return true
|
322
|
+
|
323
|
+
}
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
// editArray
|
328
|
+
|
329
|
+
func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
|
330
|
+
|
331
|
+
let targetCatStr = typesOfCatsArray[sourceIndexPath.row]
|
332
|
+
|
333
|
+
typesOfCatsArray.remove(at: sourceIndexPath.row)
|
334
|
+
|
335
|
+
typesOfCatsArray.insert(targetCatStr, at: destinationIndexPath.row)
|
336
|
+
|
337
|
+
typeOfCatsTableView.reloadData()
|
338
|
+
|
339
|
+
}
|
340
|
+
|
341
|
+
}
|
342
|
+
|
343
|
+
```
|
4
追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
|
16
16
|
|
17
|
-
そもそも、このチェックマークの使い道自体が間違っているのか
|
17
|
+
以前教えていただいたUILabelを使用して作ったものを、このチェックマークに置き換えたいと思うのですが、そもそも、このチェックマークの使い道自体が間違っているのでしょうか?
|
18
18
|
|
19
19
|
|
20
20
|
|
@@ -216,16 +216,12 @@
|
|
216
216
|
|
217
217
|
|
218
218
|
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
219
|
![イメージ説明](a6b32116a564810eb6f68c3e34553fd6.gif)
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
↓UILabelを使用して作ったもの。
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
![イメージ説明](bfaecea3d2facff54435b2bdc34a4f09.gif)
|
3
訂正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
tableViewCell
|
1
|
+
tableViewCell 左端のチェックマークを維持したい。
|
test
CHANGED
@@ -2,15 +2,19 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
-
常時並び替え可能なテーブルビューにチェックマークを設定したところ、並び替え処理後に、チェックマークが維持できなくて困っています。
|
5
|
+
常時並び替え可能なテーブルビューにチェックマークを設定したところ、~~並び替え処理後に、チェックマークが維持できなくて困っています。~~
|
6
|
+
|
6
|
-
|
7
|
+
TableViewリロード時に、チェックマークが維持できなくて困っています。
|
8
|
+
|
9
|
+
|
10
|
+
|
7
|
-
|
11
|
+
UserDefaultなどをつかった、チェック済セルの永続化に必要なので、
|
8
12
|
|
9
13
|
tableView.allowsMultipleSelectionDuringEditing = true に設定した際にチェックマークの状態を示すセルのプロパティ名をご存知でしたら教えてください。
|
10
14
|
|
11
15
|
|
12
16
|
|
13
|
-
そもそも、このチェックマークの使い道自体が間違っているのかもしれませんが
|
17
|
+
そもそも、このチェックマークの使い道自体が間違っているのかもしれませんが…。
|
14
18
|
|
15
19
|
|
16
20
|
|
@@ -192,7 +196,11 @@
|
|
192
196
|
|
193
197
|
typesOfCatsArray.insert(targetCatStr, at: destinationIndexPath.row)
|
194
198
|
|
199
|
+
|
200
|
+
|
201
|
+
// リロードを呼ばなければチェックマークが維持される。
|
202
|
+
|
195
|
-
|
203
|
+
typeOfCatsTableView.reloadData()
|
196
204
|
|
197
205
|
}
|
198
206
|
|
2
コード訂正
test
CHANGED
File without changes
|
test
CHANGED
@@ -94,7 +94,7 @@
|
|
94
94
|
|
95
95
|
// typeOfCatsTableView.reloadData()時に、ここで選択済み配列に入っている猫の種類Cellにチェックマークを付けたいが記述方法がわからない。
|
96
96
|
|
97
|
-
if selectedCatsArray.contains(
|
97
|
+
if selectedCatsArray.contains(typeOfCatStr) == true {
|
98
98
|
|
99
99
|
//cell.isSelected = true
|
100
100
|
|
1
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -10,6 +10,10 @@
|
|
10
10
|
|
11
11
|
|
12
12
|
|
13
|
+
そもそも、このチェックマークの使い道自体が間違っているのかもしれませんが....
|
14
|
+
|
15
|
+
|
16
|
+
|
13
17
|
```swift
|
14
18
|
|
15
19
|
import UIKit
|