как с помощью кнопки вывести текст в tableView

import UIKit

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return lappedTimes.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "carCell", for: indexPath)

    cell.textLabel?.text = lappedTimes[indexPath.row]

    return cell
}

 
@IBOutlet weak var goal: UIButton!

@IBOutlet var secondLabel: UILabel!
 
@IBOutlet weak var tableview: UITableView!

private var timer: Timer!

var lappedTimes:[String] = []


 override func viewDidLoad() {
     super.viewDidLoad()
    

     
     timer = Timer.scheduledTimer(timeInterval: 1,
                                  target: self,
                                  selector: #selector(countSeconds(_:)),
                                  userInfo: nil,
                                  repeats: true)
 }
 
 @objc func countSeconds(_ sender: Timer) {
     let date = Date()
     let calendar = Calendar.current
     let hour = calendar.component(.hour, from: date)
     let minutes = calendar.component(.minute, from: date)
     let seconds = calendar.component(.second, from: date)
     let hourString = String(hour)
     let minutesString = String(minutes)
     let secondsString = String(seconds)
     
     DispatchQueue.main.async {
         self.secondLabel.text = hourString + ":" + minutesString + ":" + secondsString
     }
 }

@IBAction func goal(_ sender: UIButton) {
    let currentTime = "\(secondLabel.text!)"
    lappedTimes.append(currentTime)
}

}


Ответы (0 шт):