Swift将浮点值添加到UISlider.value

时间:2015-09-05 17:07:52

标签: ios swift uislider

import UIKit

class ViewController: UIViewController {

    // Khai bao bien
    var time:Float = 0
    var timer:NSTimer!
    var sliTime:Float!

    // End khai bao
    @IBOutlet weak var sldTime: UISlider!
    @IBOutlet weak var lblScore: UILabel!
    @IBOutlet weak var lblNum1: UILabel!
    @IBOutlet weak var lblOperator: UILabel!
    @IBOutlet weak var lblNum2: UILabel!
    @IBOutlet weak var lblResult: UILabel!
    @IBAction func btnOK(sender: AnyObject) {
    }
    @IBAction func btnCan(sender: AnyObject) {
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        sldTime.minimumValue = 0
        sldTime.maximumValue = 10
        timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("Run") ,userInfo: nil, repeats: true)
    }

    func Run()
    {
        if time == 0{
            time = 10
        }else{
            time = time - 1
            sldTime.value = time
        }
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

当我在模拟器中运行应用程序时,应用程序显示:

  

"线程1断点1.1"在行中sldTime.value =时间

1 个答案:

答案 0 :(得分:0)

调试器控制台说什么?线程1:信号SIGABRT错误,如果这是控制台所说的意味着您从主故事板到ViewController的连接不良转到插座连接>并删除您所建立的连接但它已不再使用。并尝试再次运行它。请记住,线程1:信号SIGABRT错误主要是由于Storyboard和ViewController之间的连接问题。

time = sldTime.floatValue