I made a popupviewcontroller using this tutorial: https://www.youtube.com/watch?v=FgCIRMz_3dE
And I would like when I press down the popup (with a Retry-button instead), that it should go back to the original Viewcontroller, as it does, but also restarts the "game" on the original viewcontroller automatically. So basically I want to start the game when I press "Retry" on the popup. But I only get errors when trying to reach that function..
Original Viewcontroller:
var time : Float = 0.0
var timer: NSTimer?
@IBOutlet weak var progressBar: UIProgressView!
override func viewDidLoad() {
super.viewDidLoad()
startGame()
}
func startGame() {
startTimer()
}
func startTimer() {
timer = NSTimer.scheduledTimerWithTimeInterval(0.001, target: self, selector:#selector(GameViewController.setProgress1), userInfo: nil, repeats: true)
}
func setProgress1() {
time += 0.001
progressBar.setProgress(time / 2, animated: true)
if time >= 1.9 {
endPopUp()
timer!.invalidate()
progressBar.setProgress(0.0, animated: false)
setProgress1(time = 0.0)
}
}
func endPopUp() {
let popOverVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("endPopUpID") as! PopUpViewController
self.addChildViewController(popOverVC)
popOverVC.view.frame = self.view.frame
self.view.addSubview(popOverVC.view)
popOverVC.didMoveToParentViewController(self)
}
}
As you can see, when the time reaches 1.9, the popOverVC should appear, but when the popup closes with the button in the popOverVC, I want to type: GameViewController().startGame()
But it's just giving me errors... how do I do this?