Configured Basic Functionalities and Updated Table Functions

This commit is contained in:
Dallon Archibald
2021-01-23 19:18:50 -05:00
parent 26c2b2832e
commit e0c0e24188
+38 -9
View File
@@ -37,17 +37,37 @@ class StopwatchViewController: UIViewController {
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(count), userInfo: nil, repeats: true)
}
@IBAction func stop(_ sender: UIButton) {
}
@IBAction func reset(_ sender: UIButton) {
}
@IBAction func lap(_ sender: UIButton) {
}
@objc fileprivate func count() {
seconds += 1
print(seconds)
if seconds == 60 {
minutes += 1
seconds = 0
}
if minutes == 60 {
hours += 1
minutes = 0
}
if hours == 24 {
timer.invalidate()
}
secondLabel.text = "\(seconds)" //if time, make it display 01, 02...
minuteLabel.text = minutes == 0 ? "00" : "\(minutes)"
hourLabel.text = hours == 0 ? "00" : "\(hours)"
}
@IBAction func stop(_ sender: UIButton) {
timer.invalidate()
}
@IBAction func reset(_ sender: UIButton) {
}
@IBAction func lap(_ sender: UIButton) {
let currentTime = "\(hours):\(minutes):\(seconds)"
lappedTimes.append(currentTime)
let indexPath = IndexPath(row: lappedTimes.count - 1, section: 0)
tableView.insertRows(at: [indexPath], with: .automatic)
}
}
@@ -60,6 +80,15 @@ extension StopwatchViewController: UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "lapCell", for: indexPath)
cell.textLabel?.text = lappedTimes[indexPath.row]
cell.selectionStyle = .none
return cell
}
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
lappedTimes.remove(at: indexPath.row)
tableView.deleteRows(at: [indexPath], with: .automatic)
}
}
}