xcode 错误:UIView 的窗口不等于另一个视图的窗口

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25677447/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 05:29:16  来源:igfitidea点击:

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

iosxcodeuiviewswiftwindow

提问by paka

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

我是一个学习 swift 的初学者程序员。第一次在这里发帖。

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.

额外的信息,但可能是不必要的
在我创建的这个应用程序中,用户在主视图控制器上选择一个图像并将其传递给第二个视图控制器。在那里图像被分解成碎片,这些碎片被放置在单独的 UIImageViews 中。目标是通过交换图像将它们按正确的顺序排列。

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.

一切正常,在模拟器中运行正常。但是,我正在尝试添加基本动画(移动 UIImageViews),但它们没有执行。我知道我有正确的动画语法,因为我在另一个项目中测试了代码。

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!

2014-09-04 17:51:33.489 TileGame[79951:95150647] UIView:0x7f7fe9c84600;框架 = (0 0; 320 568); 自动调整大小 = W+H;layer = CALayer: 0x7f7fe9c848d0>> 的窗口不等于 TileGame.GameScreen: 0x7f7fe9dc6bc0> 的视图窗口!

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:

看起来这个人有一个类似的错误消息,但可能比我的应用程序更复杂。模态视图控制器 UI 在presentViewController:animated:completion 之后没有响应:

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

这是我在 GitHub 上的整个项目:https: //github.com/pakalewis/Parker-Lewis-CF/tree/master/TileGame

Thanks

谢谢

回答by rdelmar

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.

您似乎对 iOS 编程范式有一些根本性的误解。您的按钮上附加了 segue,但您也可以在代码中调用 performSegue。当您将转场附加到控件时,您不需要任何代码(也不应该有任何代码)来执行转场。除了展开转场之外,您也不应该使用转场返回到先前的视图控制器;您并没有真正返回,而是创建了一个您认为要返回的控制器的新实例。这将导致控制器的建立(因为不会释放任何控制器),直到您的应用程序内存不足为止。

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).

因此,您应该从 MainScreen 中删除函数letsPlayButton:,并在情节提要中删除它(您只需要附加到该按钮的 segue)。

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

删除您从 GameScreen“返回”到 MainScreen 的 segue,并将 backToMainScreen 中的代码更改为此,

@IBAction func backToMainScreen(sender: AnyObject) {
        self.dismissViewControllerAnimated(true, completion: nil)
    }