解雇多个UIViews的正确方法?

时间:2015-11-19 16:11:58

标签: ios objective-c uiview uiviewcontroller

我有一个UIViewController(HomeView),通过Segue显示我的UIView名为GameView。

[self performSegueWithIdentifier: @"segue_playgame" sender: self];

当使用按下按钮时,GameView会调用UIView(PauseView)。只需将PauseView添加到UIView即可显示此暂停视图。

UIView *pv = [[PauseView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:pv];

要删除我调用的PauseView

[pv removeFromSuperview];

有没有办法在PauseView中调用“结束游戏”方法,该方法将删除PauseView和GameView,将用户带回HomeView(UIViewController)?

请注意,是否有更好的方法来处理显示视图并将其删除?或者我是如何做到这几乎是标准的?

enter image description here

1 个答案:

答案 0 :(得分:1)

这里缺少的是UINavigationController。来自official documentation

  

UINavigationController类实现了一个专门的视图   管理分层内容导航的控制器。这个   导航界面可以显示您的数据   有效地使用户更容易导航该内容。   您通常按原样使用此类,但您也可以子类化   自定义类行为。

您可以使用UINavigationController堆栈管理您的观看次数:

- (NSArray<__kindofUIViewController *> *)popToRootViewControllerAnimated:(BOOL)animated

回弹到根视图控制器,在你的情况下是你的家庭视图控制器。