好的,所以我在Swift工作,我有我的ViewController和我的游戏场景视图,因为它是一个精灵套件游戏。现在我的View Controller中有一个NSTimer
从3倒数。当它达到0时,计时器停止。在这里,我做到了这一点:
@IBOutlet weak var countdownTestLabel: UILabel!
var countdown = NSTimer()
var counter = 3
func updateCounter() {
countdownTestLabel.text = String(counter--)
if counter == 0 {
countdown.invalidate()
//Then trigger segue to Game Scene view
}
}
override func viewDidLoad() {
super.viewDidLoad()
//Setting up countdown timer
countdownTestLabel.font = UIFont(name: "DIN Condensed", size: 30)
countdownTestLabel.text = "\(counter)"
countdown = NSTimer.scheduledTimerWithTimeInterval(1, target:self, selector: Selector("updateCounter"), userInfo: nil, repeats: true)
当计时器停止时,我需要执行加载我的游戏场景视图的segue。我知道如何使用按钮(控制拖动)来执行此操作,但我需要以编程方式执行此操作。
我尝试过做self.presentViewController(secondViewController, animated: true, completion: nil)
这样的事情,但我不知道如何将secondViewController
定义为我的游戏场景而且我遇到了错误。我该怎么办?
答案 0 :(得分:1)
你有几个选择。
您可以控制 - 从源视图控制器拖动到目标视图控制器并创建视图控制器级别segue。然后,您将为其提供唯一标识符,然后使用performSegueWithIdentifier:sender:
来调用它。
另一个选项是为视图控制器的场景提供唯一标识符,使用instantiateViewControllerWithIdentifier:
创建该视图控制器的实例,然后使用`presentViewController:animated:'