小编Tha*_*guy的帖子

无法识别的选择器发送到实例NSTimer Swift

我正在尝试开发一个包含简单秒表功能的应用程序.我正在使用Xcode 6和Swift语言.这是FirstViewController中的代码

@IBAction func Stopwatch (Sender:UIButton) { 

var startTime = NSTimeInterval()

    func updateTime(timer:NSTimer) {

        //Find Current TIme

        var currentTime = NSDate.timeIntervalSinceReferenceDate()

        //Find the difference between current time and start time

        var elapsedTime :NSTimeInterval = currentTime - startTime

        //calculate the minutes in elapsed time.
        let minutes = UInt(elapsedTime / 60.0)
        elapsedTime -= (NSTimeInterval(minutes) * 60)

        //calculate the seconds in elapsed time.
        let seconds = UInt(elapsedTime)
        elapsedTime -= NSTimeInterval(seconds)

        //find out the fraction of milliseconds to be displayed.
        let hours = UInt(elapsedTime …
Run Code Online (Sandbox Code Playgroud)

stopwatch nstimer ios swift

7
推荐指数
2
解决办法
3462
查看次数

标签 统计

ios ×1

nstimer ×1

stopwatch ×1

swift ×1