-1

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!

  • Now, the real problem is: there are no errors in the code, but my app is not working according to the code I have written. For ex: If my right Counter is 5, I know it's 5, it should take me to the Level2 VC, but it's still taking me to the Level1 VC. Please help! – Shaham Kampala Aug 23 '15 at 01:11
  • Is it maybe because, my rightCounter value stored in one view controller is not accessible by the MainViewController ? – Shaham Kampala Aug 23 '15 at 01:17
  • I did put a breakpoint at the starting of second if command. Now there's that green highlight showing Thread1: Breakpoint. The app got stuck, and it's saying this `GuessMeFinal[1893:1599218] Could not load the "" image referenced from a nib in the bundle with identifier "com.SKApps.GuessMeFinal"` What does that mean ? – Shaham Kampala Aug 23 '15 at 01:20
  • And to be clear, I have stored the rightCounter value in Level1 VC & Level2 VC but not in the MainViewController. Will that be a problem ? – Shaham Kampala Aug 23 '15 at 01:21
  • @matt Help me out here.! Please..! – Shaham Kampala Aug 23 '15 at 01:25
  • So how to resolve the ViewController issue ? – Shaham Kampala Aug 23 '15 at 12:19
  • So, @matt what do you think might be the reason the Level2 VC is not presented while [Play] button is clicked ? – Shaham Kampala Aug 23 '15 at 12:26
  • Any help please ? It's simple : The code is not working..! But no errors..! Please help me out here..! – Shaham Kampala Aug 24 '15 at 22:54
  • Now I understood the problem.>! When I'm calling rightCounter, it's not being called rightly from Level1 ViewController. So how to call stored value from another ViewController ? – Shaham Kampala Aug 25 '15 at 07:26
  • Umm..now the problem is..Like, now..I got 2 files : ViewController.swift & Level1.swift. In Level1.swift I have set the rightCounter: Int = 0 outside the UIViewControllerClass. So it's public. And then I got to ViewController.swift and call the rightCounter inside an IBAction using an 'if' command. All works fine. No errors, but the problem is that :When I click the IBAction Button I get the value '0' returned eventhough the value gets updated in Level1.swift. Any ways to solve that problem..please help..? – Shaham Kampala Aug 25 '15 at 15:35
  • I notice one thing: The 1st ViewController is always returning the "0" value. The values are okay with other ViewController. So, what might be the problem..! Help Me..Please..! – Shaham Kampala Aug 25 '15 at 21:09

1 Answers1

0

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: storyboard enter image description here

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.

Community
  • 1
  • 1
Jake
  • 319
  • 1
  • 7
  • 21