-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathViewController.swift
74 lines (61 loc) · 2.84 KB
/
ViewController.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
69
70
71
72
73
//
// ViewController.swift
// Wordle
//
// Created by Mari Batilando on 2/12/23.
//
import UIKit
class ViewController: UIViewController,
SettingsViewControllerDelegate {
@IBOutlet weak var wordsCollectionView: UICollectionView!
@IBOutlet weak var keyboardCollectionView: UICollectionView!
private var boardController: BoardController!
private var keyboardController: KeyboardController!
private let segueIdentifier = "SettingsViewControllerSegue"
override func viewDidLoad() {
super.viewDidLoad()
setupNavigationBar()
boardController = BoardController(collectionView: wordsCollectionView)
keyboardController = KeyboardController(collectionView: keyboardCollectionView)
keyboardController.didSelectString = { [unowned self] string in
if string == kDeleteKey {
self.boardController.deleteLastCharacter()
} else {
self.boardController.enter(string)
}
}
let rightBarButtonItem = UIBarButtonItem(title: "Settings",
style: .plain,
target: self,
action: #selector(didTapSettingsButton))
rightBarButtonItem.tintColor = .white
navigationItem.rightBarButtonItem = rightBarButtonItem
let leftBarButtonItem = UIBarButtonItem(title: "Reset",
style: .plain,
target: self,
action: #selector(didTapSettingsButton))
leftBarButtonItem.tintColor = .white
navigationItem.leftBarButtonItem = leftBarButtonItem
// Exercise 5 Pt. 1 (optional): Add a button on the left-hand side of the navigation bar to reset the
// game with the current settings
// Tip 1: Look at how the `rightBarButton` is created and use it as an example. You may create a new
// function that gets called similar to `didTapSettingsButton`. Make use of the online documentation and
// CMD + click to learn more about what methods and properties you can use
// Tip 2: You'll want to use and implement `resetBoardWithCurrentSettings` inside of BoardController.swift
// in the function that you fire when the button is tapped
// START YOUR CODE HERE
// ...
// END YOUR CODE HERE
}
@objc private func didTapSettingsButton() {
performSegue(withIdentifier: segueIdentifier, sender: nil)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
guard segue.identifier == segueIdentifier else { return }
let settingsViewController = segue.destination as! SettingsViewController
settingsViewController.delegate = self
}
func didChangeSettings(with settings: [String: Any]) {
boardController.resetBoard(with: settings)
}
}