简体   繁体   English

如何重新加载整个类和UIView?

[英]how can i reload an entire class and UIView?

im trying to design a very simple game. 我试图设计一个非常简单的游戏。 Once the user finishes the first level, I would like to allow the player to click a "retry level" button, how do I make the UIView and all of it's data reload as if it were the first time the UIView is called? 用户完成第一个级别后,我想允许播放器单击“重试级别”按钮,如何制作UIView及其所有数据,就像第一次调用UIView一样?

Thanks 谢谢

The simplest way is to kill the existing view and create another one. 最简单的方法是杀死现有视图并创建另一个视图。

BTW: this is your architecture error, cause UIView (and any of it's subclases) is intended to display smth, it should not store any data. 顺便说一句:这是您的架构错误,因为UIView(及其任何子类别)旨在显示smth,因此不应存储任何数据。 You have to create some back end class. 您必须创建一些后端类。 Smth like MyGameController, which has to control all the gameplay and also load/reload levels or whatever. 像MyGameController这样的东西,它必须控制所有游戏玩法,还必须加载/重新加载级别或其他内容。

You can reload UIView using: 您可以使用以下方法重新加载UIView:

YourViewController *name = [[YourViewController alloc]initWithNibName:@"YourViewController" bundle:nil];
[self.navigationController pushViewController:name animated:NO];

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM