问题
Okay..here's the problem. When I click the [Play] button in the main menu, it should go to the corresponding ViewController according to this code:
@IBAction func playButton(sender: AnyObject) {
if rightCounter <= 4 {
if let Level1 = self.storyboard!.instantiateViewControllerWithIdentifier("Level1") as? Level1 {
self.presentViewController(Level1, animated: true, completion: nil)
}
}
if rightCounter >= 5 && rightCounter <= 9 {
if let Level2 = self.storyboard!.instantiateViewControllerWithIdentifier("Level2") as? Level2 {
self.presentViewController(Level2, animated: true, completion: nil)
}
}
}
The code works perfect! No errors! But when the rightCounter is 9, it still takes me to the first ViewController. Actually it should be taking me to the second ViewController. That's where we have to fix. Btw, thanks in advance.
And during that time, I get this error too..
Warning: Attempt to present <GuessMeFinal.Level2: 0x79eb7500> on <GuessMeFinal.ViewController: 0x7ac62180> whose view is not in the window hierarchy!
I have connected the mainViewController to the Level1 and Level2 ViewControllers. So, should I use another code to solve my problem, or please help me out here!
回答1:
I have had this problem before. It happens when you try to present a view controller that is not embedded in the same navigation/tab bar controller.
This will fail:
If you try to present the highlighted segue your app will crash. I don't know if this is what you are trying to do but I have encountered this error before. You may also want to look at this very similar question.
Hope this helps.
来源:https://stackoverflow.com/questions/32150707/warning-attempt-to-present-guessmefinal-on-guessmefinal-viewcontroller-whos