Error: UIView's window is not equal to another view's window

12,214

You seem to have some fundamental misunderstandings of iOS programming paradigms. You have segues attached to your buttons, but you also then call performSegue in code. When you have a segue attached to a control, you don't need any code (and shouldn't have any) to cause the segue to execute. You also shouldn't go back to a previous view controller with a segue, other than an unwind segue; you're not really going back, you're creating a new instance of the controller you think you're going back to. This will cause a build up of controllers (as none will be deallocated) until your app runs out of memory.

So, you should delete the function, letsPlayButton: from MainScreen, and also get rid of it in the storyboard (the segue attached to that button is all you need).

Delete the segue you have going "back" from GameScreen to MainScreen, and change the code in backToMainScreen to this,

@IBAction func backToMainScreen(sender: AnyObject) {
        self.dismissViewControllerAnimated(true, completion: nil)
    }
Share:
12,214
paka
Author by

paka

Updated on June 08, 2022

Comments

  • paka
    paka almost 2 years

    I am a beginner programmer learning swift. First post here.

    Extra info but maybe unnecessary
    In this app I created, the user chooses an image on the main View controller and passes it to the second view controller. There the image is broken up into pieces and those pieces are placed in separate UIImageViews. The objective is to put them in the right order by swapping images.

    Everything is working fine and it runs ok in the simulator. However, I am trying to add basic animations (moving the UIImageViews) but they are not performing. I know I have the correct syntax for the animation because I tested the code in another project.

    Main question
    When I navigate from my main view controller to second view controller, an error immediately appears in the console. Here's what it says:

    2014-09-04 17:51:33.489 TileGame[79951:95150647] UIView: 0x7f7fe9c84600; frame = (0 0; 320 568); autoresize = W+H; layer = CALayer: 0x7f7fe9c848d0>>'s window is not equal to TileGame.GameScreen: 0x7f7fe9dc6bc0>'s view's window!

    I can't figure out what it means but it does not seem to be causing any problems except for impeding the animation. Any ideas??

    Looks like this person had a similar error message but maybe more complicated than my app. Modal viewcontroller UI not responsive after presentViewController:animated:completion:

    Here's my whole project on GitHub: https://github.com/pakalewis/Parker-Lewis-CF/tree/master/TileGame

    Thanks

  • paka
    paka over 9 years
    That did the trick. The error message must have come from creating multiple controllers on top of each other. I'm just starting out with iOS stuff and programming in general so the segues have been causing me some confusion - makes a lot more sense now. Thanks for taking the time to answer!