2015-06-21 54 views
-3

我做了一個計時器,然後我添加了一個滑塊,其中顯示了它的值。我想要做的是讓我的最後一個標籤(Moneyadded)顯示滑塊值乘以NStimer當前的秒數。嘗試將滑塊的變量乘以NSTimer變量。

import UIKit 

class ViewController: UIViewController { 

var timercount = 0 
var timerRunning = false 
var timer = NSTimer() 
var myVaribale: Int = 0 

override func viewDidLoad() { 
    timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("update"), userInfo: nil, repeats: true) 
} 

func update() { 
    // fired once a second 
    myVaribale += 258 
} 



@IBOutlet weak var timerlabel: UILabel! 

func counting(){ 

    timercount += 1 
    timerlabel.text = "\(timercount)" 
    var timerValue = timercount.value 

} 

@IBAction func Clockin(sender: UIButton) { 
    if timerRunning == false{ 
     timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("counting"), userInfo: nil, repeats: true) 
     timerRunning = true 
    } 
} 


@IBAction func Clockout(sender: UIButton) { 
    if timerRunning == true{ 
     timer.invalidate() 
     timerRunning = false 
    } 

} 


@IBAction func Restart(sender: UIButton) { 
    timercount = 0 
    timerlabel.text = "0" 
} 



@IBOutlet weak var Slider: UISlider! 


@IBOutlet weak var Label: UILabel! 

@IBAction func valuechanged(sender: UISlider) { 
var currentValue = Int(Slider.value) 

    Label.text = "\(currentValue)" 

} 

@IBOutlet weak var Moneyadded: UILabel! 
\\this is for the label (text) that I want the NStimer to be multiplied by the slider value. 
+0

請只顯示相關代碼段還你試過,但沒有奏效。 – LinusGeffarth

回答

0

更改counting功能如下:

/** Gets triggered once every second */ 
func counting(){ 
    timercount += 1 
    timerlabel.text = "\(timercount)" 
    Moneyadded.text = "\(timercount * Int(Slider.value))" 
}