ViewDidAppear 在基于选项卡栏的应用程序中未调用

发布于 2024-12-04 01:50:56 字数 524 浏览 0 评论 0原文

我有一个问题。我正在开发一个基于选项卡栏的应用程序。在此应用中,当我们想要导航到新视图时,我们会调用 [self.view addSubview:newVC.view]。 newVC 是我们要显示的新视图的视图控制器。当我们想返回到上一个视图时,我们还可以使用[self.view removeFromSuperview]

换句话说,没有导航控制器。现在的问题是我想更新以前的视图。由于我们使用 [self.view removeFromSuperview],前一个视图的 viewDidAppear 不会被调用,因此我们无法刷新该视图。

我知道我们使用的方法有缺陷,但由于它是一个大型应用程序,并将其更改为实现导航控制器需要花费大量时间,所以我需要您帮助我找到这个问题的解决方案。如何从其子视图调用 [self.view removeFromSuperview] 时调用 viewDidLoadviewDidAppear 或上一个视图?

I have a problem. I am working on an app which is tab bar based app. In this app, we call [self.view addSubview:newVC.view] when we want to navigate to a new view. newVC is the view controller of the new view that we want to display. Also we use [self.view removeFromSuperview] when we want to go back to previous view.

So in other words, there is no navigation controller. Now problem is that I want to update the previous view. Since we are using [self.view removeFromSuperview], viewDidAppear of the previous view is not get called and so we have no way of refreshing that view.

I know the approach that we used has flaw but since its a large scale app and changing it to implement navigation controller with take lot of time so I need you to please help me find the solution of this problem. How can I call the viewDidLoad or viewDidAppear or the previous view on calling [self.view removeFromSuperview] from its subview?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

深海不蓝 2024-12-11 01:50:56

是的,正如莎拉所说,您应该在“堆栈”中保留对先前控制器的引用。
当从堆栈中“弹出”控制器时,调用前一个控制器上的适当方法。
当然你不应该调用viewDidLoad(当你从真实的UINavigationController的导航堆栈中弹出控制器时它不会被调用)。
您可以调用 viewWillAppearviewDidAppear,但最好使用您自己的方法,例如 viewRevealed(您也可以从 viewWillAppearviewDidAppear 调用它)。制作起来很有用
基类实现所有这些功能并从基类派生所有控制器。它可能看起来像:

- (void) pushViewController:(BaseViewController *)baseController{
  [self.view addSubview:baseController.view];
  baseController.parentController = self;
}
- (void) pop{
  [self.view removeFromSuperview];
  [self.parentController viewRevealed];
}

Yes, as Sarah said you should hold a reference to previous controller in "stack".
And when "poping" controller from stack, call appropriate method on previous controller.
Certainly you should not call viewDidLoad (it is not called when you pop controller from navigation stack of real UINavigationController).
You can call viewWillAppear or viewDidAppear, but better use your own method, like viewRevealed (you can also call it from viewWillAppear or viewDidAppear). It is useful to make
base class where implement all this functionality and derive all you controller from the base class. It may look like:

- (void) pushViewController:(BaseViewController *)baseController{
  [self.view addSubview:baseController.view];
  baseController.parentController = self;
}
- (void) pop{
  [self.view removeFromSuperview];
  [self.parentController viewRevealed];
}
旧城空念 2024-12-11 01:50:56

viewDidLoad 方法仅在您通过 pushViewController 方法跳转到控制器时调用。如果您调用removeFromSupreView,它将调用viewWillAppear方法。在这里,如果您想通过选项卡栏从一个视图导航到另一个视图,则必须在 Mainwindow.xib 中使用 UINavigationController 并将其 viewController 与 App delegate 连接。

viewDidLoad method call only when when you jump into a controller through pushViewController method. If you call removeFromSupreView, it will call viewWillAppear method. Here if you want to navigate from one view to another view over tabbar you must use UINavigationController in Mainwindow.xib and connect its viewController with App delegate.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文