Приложение Stop Watch в Swift 11 (Новое в мире кодирования) - PullRequest
0 голосов
/ 27 апреля 2020

Я получаю 4 разных сообщения об ошибках.

  1. Тип «StopWatchViewController» не соответствует протоколу «UITableViewDataSource»
  2. В объявлении «StopWatchViewController»
  3. Использование неразрешенного идентификатора 'UITabelViewCell'
  4. Использование неразрешенного идентификатора 'UITabelViewCellStyle'

//

import UIKit

class StopWatchViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {


    var laps: [String] = []

    var timer = Timer()
    var minutes: Int = 0
    var seconds: Int = 0
    var fractions: Int = 0

    var stopwatchString: String = ""

    var startStopWatch: Bool = true
    var addLap: Bool = false


    @IBOutlet weak var stopWatchLabel: UILabel!
    @IBOutlet weak var lapsTableView: UITableView!
    @IBOutlet weak var startStopButton: UIButton!
    @IBOutlet weak var lapResetButton: UIButton!


    @IBAction func startStop(_ sender: AnyObject) {

        if startStopWatch == true {

            timer = Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: Selector(("updateStopWatch")), userInfo: nil, repeats: true)
            startStopWatch = false

            addLap = true

        }else {

            timer.invalidate()
            startStopWatch = true

            addLap = false
        }
    }

    @IBAction func lapReset(_ sender: AnyObject) {
    }
   if addLap == true {

    laps.insert(stopwatchString, atIndex: 0)
    lapsTableView.reloadData()

    }else {

    addLap = false

    fractions = 0
    seconds = 0
    minutes = 0

    stopwatchString = "00:00.00"
    stopwatchLabel.text = stopwatchString

    }


    override func viewDidLoad() {
        super.viewDidLoad()

        stopWatchLabel.text = "00:00.00"

        // Do any additional setup after loading the view.
    }

  override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()

    }

    func updateStopwatch() {

        fractions += 1
        if fractions == 100 {

            seconds += 1
            fractions = 0

        }

        if seconds == 60 {

            minutes += 1
            seconds = 0
        }

        let fractionsString = fractions > 9 ? "\(fractions)" : "0\(fractions)"
        let secondsString = seconds > 9 ? "\(seconds)" : "\(seconds)"
        let minutesString = minutes > 9 ? "\(minutes)" : "0\(minutes)"

        stopwatchString = "\(minutesString):\(secondsString).\(fractionsString)"
        stopWatchLabel.text = stopwatchString
    }

    //Table View Methods

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

    func tableView(_ tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

        var cell = UITabelViewCell(style: UITabelViewCellStyle.Value1, reuseIdentifier: "Cell")

        cell.backgroundColor = self.view.backgroundColor
        cell.textLabel.text = "Lap \(indexPath.row)"
        cell.detailTextLabel?.text = laps[indexPath.row]

        return cell

    }


}

1 Ответ

0 голосов
/ 27 апреля 2020
  • Ваш метод cellForRow не имеет правильной подписи, он должен быть func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell

  • UITabelViewCell должен быть написан UITableViewCell

  • UITabelViewCellStyle должно быть написано UITableViewCellStyle

Вы должны проверить свое правописание, большинство ошибок времени связано с ним.

...