错误:UIView的窗口不等于另一个视图的窗口 [英] Error: UIView's window is not equal to another view's window

查看:78
本文介绍了错误:UIView的窗口不等于另一个视图的窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个学习敏捷的初学者.第一篇文章在这里.

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

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

主要问题
当我从主视图控制器导航到第二个视图控制器时,控制台中立即出现错误.它是这样的:

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

我不知道这意味着什么,但除了阻碍动画外,它似乎没有引起任何问题.有什么想法吗?

看起来这个人有类似的错误消息,但可能比我的应用程序复杂. modal viewcontroller UI在pre​​sentViewController:animated:completion:之后无响应>

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

谢谢

解决方案

您似乎对iOS编程范例有一些基本的误解.您已经将segue附加到按钮上,但是您还可以在代码中调用performSegue.当将segue附加到控件时,不需要任何代码(也应该没有任何代码)来使segue执行.您也不应使用放松功能返回到以前的视图控制器,而要放松放松.您并没有真正回去,而是在创建您认为要回去的控制器的新实例.这将导致控制器的建立(因为不会释放控制器),直到您的应用程序内存不足为止.

因此,您应该从MainScreen删除函数letPlayButton :,并在情节提要中删除它(您只需要与该按钮相连的segue)即可​​.

将要返回"的序列从GameScreen删除到MainScreen,然后将backToMainScreen中的代码更改为此,

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

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

解决方案

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

这篇关于错误:UIView的窗口不等于另一个视图的窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆