我有一个 UIViewController (HomeView),它通过 Segue 显示我的名为 GameView 的 UIView。
[self performSegueWithIdentifier: @"segue_playgame" sender: self];
当用户按下按钮时,GameView 调用 UIView (PauseView)。只需将 PauseView 添加到 UIView 即可显示此暂停 View 。
UIView *pv = [[PauseView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:pv];
删除我调用的 PauseView
[pv removeFromSuperview];
有没有办法在 PauseView 中调用“结束游戏”方法,这将同时删除 PauseView 和 GameView,使用户返回 HomeView (UIViewController)?
旁注,是否有更好的方法来处理 View 的显示和删除?还是我的做法非常标准?
最佳答案
您在这里缺少的是 UINavigationController
。来自official documentation :
The UINavigationController class implements a specialized view controller that manages the navigation of hierarchical content. This navigation interface makes it possible to present your data efficiently and makes it easier for the user to navigate that content. You generally use this class as-is but you may also subclass to customize the class behavior.
通过 UINavigationController
堆栈管理您的 View ,您可以使用:
- (NSArray<__kindofUIViewController *> *)popToRootViewControllerAnimated:(BOOL)animated
返回到 Root View Controller ,在您的情况下是您的主视图 Controller 。
关于ios - 关闭多个 UIView 的正确方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33808963/