简体   繁体   中英

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. When on the game view controller, the player can take their turn, then access Game Center on the same view. Then once in Game Center they can start a new game (or look at other games they have going). 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. 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. Each index of the array could store an instance of a view or viewcontroller, depending on your algorithm. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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