Dies ist mein Code Dies zeigt einen Fehler hier. Was kann ich dagegen tun?Zwei Fehler im Code
class ViewController: UIViewController, UITabBarDelegate, UITableViewDataSource {
var laps: String = String() // just written the thing above bcz SO was complaining
var timer = Timer()
var minutes: Int = 0
var seconds: Int = 0
var fractions: Int = 0
var startstopwatch = true
var addLap = false
var stopWatchString: String = ""
@IBOutlet var stopWatchLabel: UILabel!
@IBOutlet var lapsTableView: UITableView!
@IBOutlet var startsTopButton: UIButton!
@IBAction func startstop(_ sender: Any) {
if startstopwatch == true{
timer = Timer.scheduledTimer(timeInterval: 0.01, target: self, selector: #selector(ViewController.updateStopWatch), userInfo: nil, repeats: true)
startstopwatch = false
startsTopButton.setTitle("Stop", for: UIControlState.normal)
lapresetBtn.setTitle("Lap", for: UIControlState.normal)
addLap = true
}else {
timer.invalidate()
startstopwatch = true
startsTopButton.setTitle("Start", for: UIControlState.normal)
lapresetBtn.setTitle("Reset", for: .normal)
addLap = false
}
}
@IBOutlet var lapresetBtn: UIButton!
@IBAction func lapreset(_ sender: Any) {
if addLap == true {
laps.insert("\(stopWatchString)", at: 0)
lapsTableView.reloadData()
}else {
addLap = false
lapresetBtn.setTitle("Lap", for: .normal)
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, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
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)" : "0\(seconds)"
let minuteString = minutes > 9 ? "\(minutes)" : "0\(minutes)"
stopWatchString = "\(minuteString):\(secondsString).\(fractionsString)"
stopWatchLabel.text = stopWatchString
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: UITableViewCellStyle.value1, reuseIdentifier: "Cell")
cell.backgroundColor = self.view.backgroundColor
cell.textLabel?.text = "Lap \(indexPath.row)"
cell.detailTextLabel?.text = laps[indexPath.row + 1]//Subscript is unavailable. there is no universally good reason check documentation for more details
return cell
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return laps.count // count is unavailable. there is no universally good reason. check documentation for more details
}
Sie dachten wahrscheinlich, dass "Runden" ein '[String]' sind, kein 'String'. – Hamish