viewWillAppear 仅被调用一次

发布于 2024-10-18 08:38:09 字数 215 浏览 5 评论 0原文

这是场景,switchViewController 是添加到主窗口的视图。所以 switchViewController 是主视图,所以如果我想去视图 B,我会添加视图 B 的子视图,不需要删除 switchViewController 的视图,对吗? 问题是当我从视图 B 返回到 switchViewController 的视图后,viewWillAppear 方法不再被调用。

为什么会这样呢?

Here's the scenario, switchViewController is the view added to the main window. So switchViewController is the main view, so if I want to go view B, I will addsubview of view B, there isn't a need to remove switchViewController's view right?
The issue is after I go back from view B to switchViewController's view, the method viewWillAppear is not being called anymore.

Why is it so?

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

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

发布评论

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

评论(3

动次打次papapa 2024-10-25 08:38:09

viewWillAppear: 当视图从视图层次结构中删除或添加到视图层次结构时,不会自动调用。视图控制器有责任在正确的时间调用它。每当您呈现或推送新的视图控制器时,内置视图控制器类都会执行此操作。由于您不在应用程序中使用此机制,因此不会调用该方法(除非您自己调用它)。

viewWillAppear: is not called automatically when a view is removed from or added to the view hierarchy. It is the responsibility of the view controller to call it at the right time. The built-in view controller classes do this whenever you present or push a new view controller. Since you do not use this mechanism in your app, the method doesn't get called (unless you call it yourself).

桃扇骨 2024-10-25 08:38:09

那是因为它从未消失,你只是在它前面放了一些别的东西。如果您想从一个屏幕导航到另一个屏幕并返回,它们应该是单独的视图控制器,并且您应该使用 UINavigationController 及其 pushViewController:isAnimated: 方法。

That's because it never disappeared, you were just putting something else in front of it. If you want to navigate from one screen to another and back, they should be separate view controllers, and you should be using UINavigationController and its pushViewController:isAnimated: method.

愛放△進行李 2024-10-25 08:38:09

它不会被调用,因为您只是修改第一个视图,而不是导航到另一个视图。

您可能会考虑将视图嵌入到导航控制器中,然后使用以下命令调用 ViewB

[navigationController pushViewController:viewB animated:YES];

It's not getting called beause your just modifying the first view, not navigating to a different one.

You might consider embedding your view in a Navigation controller, then calling your ViewB with

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