ios - 关闭多个 UIView 的正确方法?

标签 ios objective-c uiview uiviewcontroller

我有一个 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 的显示和删除?还是我的做法非常标准?

enter image description here

最佳答案

您在这里缺少的是 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/

相关文章:

ios - UITableView 定位在 UIView 内部

ios - 解析服务器:我需要在防火墙中打开哪些端口来发送ios推送通知? (APNS)

iphone - stringFromDate 总是 NIL

iphone - 如何在 Xcode 中以编程方式清除控制台?

objective-c - 处理两个 UITextField 和委托(delegate)

iphone - 处理一个空的 UITableView。打印友好消息

objective-c - 如何在我的应用程序中的 iOS 键盘上创建自定义按钮?

ios - 如何让TNImageSliderViewController自动滑动

iphone - 具有不同值的 TableView 委托(delegate)方法中的索引路径

objective-c - 从框架呈现模态视图时如何检测何时按下 "Done"按钮