teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

codeの入力ミス

2020/09/07 04:48

投稿

Anoa
Anoa

スコア10

answer CHANGED
@@ -1,33 +1,5 @@
1
1
  ```Swift
2
- override func viewDidLoad() {
3
- super.viewDidLoad()
4
-
5
- OnGame = true
6
- self.collectionView.delegate = self
7
- self.collectionView.dataSource = self
8
-
9
- let layout = UICollectionViewFlowLayout()
10
- layout.sectionInset = UIEdgeInsets(top: 15, left: 15, bottom: 15, right: 15)
11
- collectionView.collectionViewLayout = layout
12
-
13
- if !timer.isValid {
14
- timer = Timer.scheduledTimer(timeInterval:0.01,target: self,selector: #selector(self.down),userInfo:nil,repeats:true)
15
- }
16
-
17
- self.collectionView!.register(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)
18
- }
19
- @objc func changeColor() {
20
- let redCellIndex: Int = Int.random(in: 0..<12)
21
- collectionView.reloadData()
22
- }
23
- // 中略
24
-
25
- func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
2
+ func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
26
3
  let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath)
27
-
28
- cell.backgroundColor = self.redCellIndex == indexPath.row ? .red : .black
29
4
 
30
- return cell
31
-
32
- }
33
5
  ```