iOS学习爬坑记录15:Error: UIView's window is not equal to another view's window
2015-03-26 16:40
525 查看
今天在做页面跳转的时候犯了一个错误:在界面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
原文摘录如下:
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,
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) }
相关文章推荐
- iOS学习爬坑记录2:往NSMutableArray添加NSDictionary元素失败
- iOS学习爬坑记录8:关于自定义Cell的一点认识
- iOS学习爬坑记录3:plist文件的读写,以及向NSMutableArray中写入NSDictionary元素失败
- iOS学习爬坑记录18:ios获得设备cpu类型
- iOS学习爬坑记录20:setting bundle中的DefaultValue与registerDefaults方法注册值不一致
- iOS学习爬坑记录6: 为Xcode 6.1添加Empty Application project template
- iOS学习爬坑记录14:自定义远程推送通知铃声(Custom Alert Sounds)
- iOS学习爬坑记录10:在Storyboard中打开preview的方法
- ios学习记录 day39 UI15高级编程 XML , JSON数据结构解析
- iOS学习爬坑记录7:获取设备拥有的font family和font
- iOS学习爬坑记录12:学习Core data简单的CURD
- iOS学习爬坑记录13:查看内存使用情况的obj-c和Swift代码
- iOS学习爬坑记录19:为settings bundle添加版本号version
- iOS学习爬坑记录11:学习AsyncSocket时用python写的服务器server端简单代码
- iOS学习爬坑记录9:Xcode6.1 添加Framework
- iOS学习爬坑记录4:ios8中的搜索栏,使用UISearchController
- iOS学习爬坑记录1:为什么Xcode6中Storyboard变成了正方形?
- iOS学习爬坑记录21:'-[UITableViewController loadView] loaded the "XXX" nib but didn't get a UITableView.'
- ios学习记录 day15
- iOS学习爬坑记录17:iOS8从app跳转到设置setting bundle的方法(UIApplicationOpenSettingsURLString)