I have created a game where the main menu is contained within a normal ViewController and the actual game is played within an SKScene.
I use a modal segue from a button on the main menu to open the SKScene.
The problem I get is when I try to return from the SKScene to the main menu.
I'm using this code to present the main menu
override func touchesEnded(touches: NSSet, withEvent event: UIEvent) {
for touch: AnyObject in touches {
let location = touch.locationInNode(self)
if homeBtn.containsPoint(location)
{
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let settingController: UIViewController = storyboard.instantiateViewControllerWithIdentifier("homeViewController") as UIViewController
let vc = self.view?.window?.rootViewController
vc?.presentViewController(settingController, animated: true, completion: nil)
}
}
}
However this causes the following message:
Warning: Attempt to present ViewController on ViewController whose view is not in the window hiearchy!