Reputation: 3
underneath my timerVar.invalidate(), i want have another view controller called "SinglePlayerGameOver" loaded but i can't work out how.Basically, when the timerCount becomes bigger than 10, i want a "gameOver" screen to appear.
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)
}
}
Upvotes: 0
Views: 43
Reputation: 225
You can use this fuction
self.presentViewController(SinglePlayerGameOver, animated: true, completion: nil)
if u have navigationController, then
self.navigationController?.pushViewController(SinglePlayerGameOver, animated: true);
put this code after check the time is over 10
Upvotes: 1