iOS学习爬坑记录15:Error: UIView's window is not equal to another view's window

来源:互联网 发布:美国标志软件 编辑:程序博客网 时间:2024/05/21 14:47

今天在做页面跳转的时候犯了一个错误:在界面A添加了一个按钮,然后从这个button拖线Ctrl+drag到界面B,我为这个button添加了事件action,在这个action中使用performSegue方法跳转到界面B,运行的时候能够跳转,但是爆出打印:

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!

这个原因其实是不需要给那个button添加action,具体原因见http://stackoverflow.com/questions/25677447/error-uiviews-window-is-not-equal-to-another-views-window

原文摘录如下:

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

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






0 0
原创粉丝点击