0
下我的timerVar.invalidate(),我想要另一個視圖控制器稱爲「SinglePlayerGameOver」加載,但我不能解決如何。基本上,當timerCount變得比10大,我想要一個「gameOver」屏幕出現。如何以編程方式更改視圖控制器?
import Foundation
import UIKit
class SinglePlayer: UIViewController {
var timerCount = 0
@IBOutlet weak var timer: UILabel!
var timerVar = NSTimer()
var taps = 0
func isCounting() {
timerCount += 1
timer.text = "\(timerCount)"
if timerCount >= 10 {
timerVar.invalidate()
}
}
override func viewDidLoad() {
super.viewDidLoad()
timerVar = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: "isCounting", userInfo: nil, repeats:true)
}
}
THX!非常棒! – Noja
不錯:)對你有好處 – rnsjtngus