Configured Basic Functionalities and Updated Table Functions
This commit is contained in:
@@ -37,17 +37,37 @@ class StopwatchViewController: UIViewController {
|
|||||||
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(count), userInfo: nil, repeats: true)
|
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() {
|
@objc fileprivate func count() {
|
||||||
seconds += 1
|
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 {
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||||
let cell = tableView.dequeueReusableCell(withIdentifier: "lapCell", for: indexPath)
|
let cell = tableView.dequeueReusableCell(withIdentifier: "lapCell", for: indexPath)
|
||||||
cell.textLabel?.text = lappedTimes[indexPath.row]
|
cell.textLabel?.text = lappedTimes[indexPath.row]
|
||||||
|
cell.selectionStyle = .none
|
||||||
return cell
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user