在我的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)


}


}

最佳答案

您可以使用此功能

self.presentViewController(SinglePlayerGameOver, animated: true, completion: nil)

如果您有navigationController,则
self.navigationController?.pushViewController(SinglePlayerGameOver, animated: true);

检查时间超过10后再输入此代码

10-05 20:05