如何以编程方式更改视图控制器?

时间:2015-11-09 05:13:36

标签: ios swift

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


}


}

1 个答案:

答案 0 :(得分:1)

您可以使用此功能

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

如果你有navigationController,那么

self.navigationController?.pushViewController(SinglePlayerGameOver, animated: true);

检查时间超过10

后输入此代码