-
Notifications
You must be signed in to change notification settings - Fork 0
/
RoutinesViewController.swift
70 lines (44 loc) · 2.22 KB
/
RoutinesViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//
// ViewController.swift
// DailyRoutine
//
// Created by Aissatou Thiombane on 4/23/24.
//
import UIKit
class RoutinesViewController: UIViewController, , UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
@IBOutlet weak var collectionView: UICollectionView!
// Array to store routines
var routines = [Routine]()
override func viewDidLoad() {
super.viewDidLoad()
collectionView.delegate = self
collectionView.dataSource = self
collectionView.register(RoutineCollectionViewCell.self, forCellWithReuseIdentifier: "RoutineCell")
// Set up the plus button in the navigation bar
navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(addButtonTapped))
loadRoutines()
}
func loadRoutines() {
}
// MARK: UICollectionViewDataSource
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return routines.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "RoutineCell", for: indexPath) as! RoutineCollectionViewCell
let routine = routines[indexPath.item]
cell.titleLabel.text = routine.title
return cell
}
// MARK: UICollectionViewDelegate
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
}
// MARK: UICollectionViewDelegateFlowLayout
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let width = (collectionView.bounds.width / 2) - 16
return CGSize(width: width, height: width)
}
// MARK: - Navigation Bar Button Action
@objc func addButtonTapped() {
}
}