简体   繁体   中英

How do you programmatically change view controllers?

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)


}


}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM