2016-06-19 5 views
-1

스톱워치 앱을 만드는 중입니다. 앱에서 시작 버튼을 누르는 대신 몇 가지 이유가 있습니다. 그 대신 1,2,3,4,5 등이 있습니다. '<' . 코드를 살펴 봤지만 아무것도 찾을 수 없습니다.스톱워치 코드 문제

class ViewController: UIViewController { 

    var timer = NSTimer() 

    var time = 0 

    func result() { 
     time + 1 
     timeLabel.text = "\(timer)" 
    } 

    @IBOutlet var timeLabel: UILabel! 

    @IBAction func stop(sender: AnyObject) { 
     timer.invalidate() 

     time = 0 
     timeLabel.text = "0" 
    } 

    @IBAction func timeButton(sender: AnyObject) { 
     timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("result"), userInfo: nil, repeats: true) 
    } 

} 
+1

당신은 당신의'timeLabel.text = "\ (타이머)"오타가''timeLabel.text = "\ (시간)" '이어야한다. – vacawama

+0

그리고'time + 1'은'time + = 1'이어야합니다. – vacawama

+0

아직도 작동하지 않습니다 – Ploostic

답변

0

당신은 오타가 : timeLabel.text = "\(timer)"timeLabel.text = "\(time)"해야한다.

또한 time + 1time += 1이어야합니다. 이러한 변화와 함께, 다음과 같은 코드가 작동합니다

class ViewController: UIViewController { 

    var timer = NSTimer() 

    var time = 0 

    func result() { 
     time += 1 
     timeLabel.text = "\(time)" 
    } 

    @IBOutlet var timeLabel: UILabel! 

    @IBAction func stop(sender: AnyObject) { 
     timer.invalidate() 

     time = 0 
     timeLabel.text = "0" 
    } 

    @IBAction func timeButton(sender: AnyObject) { 
     timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: #selector(result), userInfo: nil, repeats: true) 
    } 

}