回答編集履歴

1

codeの入力ミス

2020/09/07 04:48

投稿

Anoa
Anoa

スコア10

test CHANGED
@@ -1,65 +1,9 @@
1
1
  ```Swift
2
2
 
3
- override func viewDidLoad() {
3
+ func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
4
4
 
5
- super.viewDidLoad()
6
-
7
-
8
-
9
- OnGame = true
10
-
11
- self.collectionView.delegate = self
12
-
13
- self.collectionView.dataSource = self
14
-
15
-
16
-
17
- let layout = UICollectionViewFlowLayout()
18
-
19
- layout.sectionInset = UIEdgeInsets(top: 15, left: 15, bottom: 15, right: 15)
5
+ let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath)
20
-
21
- collectionView.collectionViewLayout = layout
22
6
 
23
7
 
24
8
 
25
- if !timer.isValid {
26
-
27
- timer = Timer.scheduledTimer(timeInterval:0.01,target: self,selector: #selector(self.down),userInfo:nil,repeats:true)
28
-
29
- }
30
-
31
-
32
-
33
- self.collectionView!.register(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)
34
-
35
- }
36
-
37
- @objc func changeColor() {
38
-
39
- let redCellIndex: Int = Int.random(in: 0..<12)
40
-
41
- collectionView.reloadData()
42
-
43
- }
44
-
45
- // 中略
46
-
47
-
48
-
49
- func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
50
-
51
- let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath)
52
-
53
-
54
-
55
- cell.backgroundColor = self.redCellIndex == indexPath.row ? .red : .black
56
-
57
-
58
-
59
- return cell
60
-
61
-
62
-
63
- }
64
-
65
9
  ```