2017-02-25 2 views
-2

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 


} 
+1

Sie dachten wahrscheinlich, dass "Runden" ein '[String]' sind, kein 'String'. – Hamish

Antwort

0

Sie sollten ein Array von Strings machen Runden (Linie 3):

var laps = [String]() 

Dann Ihre Fehler gelöst werden.

1."Count ist nicht verfügbar" geworfen wurde, weil Runden ein String war, nicht ein Array von Strings und String hat keine .count Eigenschaft, hat es .characters.count

2."Tiefgestellt ist nicht verfügbar" wurde nur aus dem gleichen Grund ausgelöst, da Nicht-Array-/Nicht-Wörterbuch-/Nicht-Sammlungstypen keine Indizes (z. B. [indexPath.row + 1]) und 01 habenist einer von ihnen.

Hoffe es hilft!

Verwandte Themen