简体   繁体   English

如何将一个新的视图实例推到同一视图之上?

[英]How can I push a new instance of a view on top of the same view?

I have a turn based game that has 2 view controllers, main menu and the actual game controller. 我有一个具有2个视图控制器,主菜单和实际游戏控制器的回合制游戏。 When on the game view controller, the player can take their turn, then access Game Center on the same view. 在游戏视图控制器上时,玩家可以转弯,然后在同一视图上访问Game Center。 Then once in Game Center they can start a new game (or look at other games they have going). 然后,一旦进入Game Center,他们就可以开始一个新游戏(或查看他们正在进行的其他游戏)。 The problem I'm having is that when they choose to start a new game, and Game Center dismisses, the view has elements from the previous game. 我遇到的问题是,当他们选择开始新游戏并且Game Center被关闭时,视图具有上一个游戏的元素。 How can I start a fresh game or add a new instance of the game view controller onto the stack? 如何开始新游戏或将游戏视图控制器的新实例添加到堆栈中?

My suggestion would be to create an NSMutableArray. 我的建议是创建一个NSMutableArray。 Each index of the array could store an instance of a view or viewcontroller, depending on your algorithm. 数组的每个索引都可以存储视图或ViewController的实例,具体取决于您的算法。 When switching between views, switch between the indexes of the array. 在视图之间切换时,请在数组的索引之间切换。 Furthermore, if a new game is created, create a new instance of the view or viewcontroller and add it to the array. 此外,如果创建了新游戏,请创建视图或ViewController的新实例并将其添加到数组中。 Then, when switching between games, pull up a different index. 然后,在游戏之间进行切换时,拉出另一个索引。 This way only one index is presented at a time, and the different views are isolated from one another. 这样,一次只显示一个索引,并且不同的视图彼此隔离。 Furthermore, you can archive the data for each view in each index, so if a view is removed from screen, you could theoretically store the values of instance variables. 此外,您可以将每个索引中每个视图的数据存档,因此,如果从屏幕上删除了一个视图,则理论上可以存储实例变量的值。 Then when that view (or game) is called back by the user, create a new instance of a view or viewcontroller and populate its variables and settings according to the archived data. 然后,当用户调用该视图(或游戏)时,创建视图或ViewController的新实例,并根据存档的数据填充其变量和设置。

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

相关问题 如何在didselectrowatindexpath处推送新的表格视图? - How can I Push a new Table View at didselectrowatindexpath? 按下详细信息按钮时如何推送新视图 - How can I push a new view when detail button is presses 如何从情节提要中的子视图(另一个视图控制器)内的按钮推动新的视图控制器 - How can I push a new View Controller from a button within a subView (another View Controller) in Storyboard 如何将新的viewController推送到另一个视图控制器中的现有视图? - How can I push a new viewController into an existing view within another view controller? 如何在现有视图控制器之上部分加载新视图控制器? - How can i load a new view controller partially on top of the existing view controller? 如何在顶视图控制器中直接处理iOS推送通知? - How can I handle iOS push notification directly in my top view controller? 如何从一个视图推一个新视图controller - How to push a new view controller from a view Swift 3-推送新视图,但保持相同的NavigationBar - Swift 3 - Push a new view but keep the same NavigationBar 如何访问视图控制器的实例? - How can I access an instance of a view controller? 如何解除模态segue然后执行push segue到新视图控制器 - How can I dismiss a modal segue then perform push segue to new view controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM