不存在的视图控制器调用 viewDidAppear

发布于 2024-12-15 06:16:56 字数 1916 浏览 2 评论 0原文

我有一个导航控制器,我将其重新用于我的启动屏幕。每当我注销时,我都会将 navigationController 的 viewControllers 数组重置为单个启动屏幕。然而我遇到了一些奇怪的行为。

步骤:

Splash 出现 - 模态显示,navigationController 以单个 Splash viewController 作为根 选择“登录” - 登录视图推送到导航控制器

输入信息、提交、成功、关闭模态视图

浏览应用程序...然后再次注销

用新制作的viewController(Splash)。

呈现模态视图控制器

意外行为 ** 调用

原始“登录”视图控制器的 viewDidAppear 方法。

除了“登录”视图控制器的 viewDidAppear 被调用之外,一切都表现正常。新的启动画面出现,我可以推送新的登录,没问题。一切都照常进行。

我的 viewDidAppear 中有一个 NSNotificationCenter addObserver,因此这个额外的 viewDidAppear 被调用会导致应用程序其他地方的行为消失,这就是为什么我需要弄清楚它来自哪里并修复它。

回溯在错误的“viewDidAppear”处暂停

Thread 1, Queue : (null)
0   0x000f1881 in -[KeyboardViewController viewDidAppear:] at /Users/Me/App/Classes/KeyboardViewController.m:69
1   0x00d79fbf in -[UIViewController _setViewAppearState:isAnimating:] ()
2   0x00d7a2d4 in -[UIViewController __viewDidAppear:] ()
3   0x00d7b8c9 in __64-[UIViewController viewDidMoveToWindow:shouldAppearOrDisappear:]_block_invoke_0 ()
4   0x00d7a730 in -[UIViewController _executeAfterAppearanceBlock] ()
5   0x00cc35ea in _afterCACommitHandler ()
6   0x01dfa9ce in __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ ()
7   0x01d91670 in __CFRunLoopDoObservers ()
8   0x01d5d4f6 in __CFRunLoopRun ()
9   0x01d5cdb4 in CFRunLoopRunSpecific ()
10  0x01d5cccb in CFRunLoopRunInMode ()
11  0x0261b879 in GSEventRunModal ()
12  0x0261b93e in GSEventRun ()
13  0x00cb2a9b in UIApplicationMain ()
14  0x000028d9 in main ()

如果我在关闭导航控制器之前在导航控制器中弹出ToRootViewController,那么这个问题就会消失。但是,如果我等待 0.5 秒并在 navigationController 已经关闭后关闭,问题仍然存在。理想情况下,我不想在解雇时使用 popToRootViewController...

然后,当我在解雇之前调用 popToRootViewController 时,不会调用 viewDidDisappear 方法...现在,我已经有了一个可以拍摄快照的黑客方法当前的 viewController 堆栈,替换它们,加载视图,然后迭代存储的 Controller 堆栈,撤消在 viewDidAppear 方法中运行的代码(NSNotification 内容...)

I have a navigationController that I reuse for my Splash screen. Whenever I log out, I reset the navigationController's viewControllers array to just the single Splash screen. However I'm getting some odd behavior.

Steps:

Splash comes up - modal display, navigationController with single Splash viewController as root
Select "Sign In" - Sign In view pushes on to Nav Controller

Enter info, submit, success, dismiss modal View

Go through the app.... then Logout again

Replace modal navigationController's viewControllers (currently Splash -> Sign In) with a newly made viewController (Splash).

Present Modal ViewController

UNEXPECTED BEHAVIOR **

Original "Sign In" View Controller's viewDidAppear method gets called.

Other than the "Sign In" view controller's viewDidAppear getting called, everything behaves like normal. The new Splash comes up, I can push a new Sign In on, no problem. Everything continues as normal.

I have a NSNotificationCenter addObserver in my viewDidAppear, so this extra viewDidAppear getting called is throwing off behaviors in the app else where, which is why I need to figure out where this is coming from and fix it.

Backtrace Paused at erroneous "viewDidAppear"

Thread 1, Queue : (null)
0   0x000f1881 in -[KeyboardViewController viewDidAppear:] at /Users/Me/App/Classes/KeyboardViewController.m:69
1   0x00d79fbf in -[UIViewController _setViewAppearState:isAnimating:] ()
2   0x00d7a2d4 in -[UIViewController __viewDidAppear:] ()
3   0x00d7b8c9 in __64-[UIViewController viewDidMoveToWindow:shouldAppearOrDisappear:]_block_invoke_0 ()
4   0x00d7a730 in -[UIViewController _executeAfterAppearanceBlock] ()
5   0x00cc35ea in _afterCACommitHandler ()
6   0x01dfa9ce in __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ ()
7   0x01d91670 in __CFRunLoopDoObservers ()
8   0x01d5d4f6 in __CFRunLoopRun ()
9   0x01d5cdb4 in CFRunLoopRunSpecific ()
10  0x01d5cccb in CFRunLoopRunInMode ()
11  0x0261b879 in GSEventRunModal ()
12  0x0261b93e in GSEventRun ()
13  0x00cb2a9b in UIApplicationMain ()
14  0x000028d9 in main ()

If I popToRootViewController in the navigationController before dismissing it, this issue goes away. However, if I wait .5 seconds and dismiss once the navigationController is already dismissed, the issue persists. Ideally I don't want to popToRootViewController while it's dismissing...

Then when I was calling popToRootViewController before dismissing, the viewDidDisappear method wasn't getting called... For now, I've got a hack in place that takes a snapshot of the current stack of viewControllers, replaces them, loads the view, then iterates over the stored stack of Controllers, undoing the code that runs in the viewDidAppear method (NSNotification stuff...)

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

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

发布评论

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

评论(2

肤浅与狂妄 2024-12-22 06:16:57

正如你所说

每当我注销时,我都会重置 navigationController 的 viewControllers
数组到单个启动屏幕。

这表明您再次设置 navigationController 的 viewController,而不是 NavigationController 本身。

发生这种情况是因为每当我们将新视图控制器的数组放入导航堆栈时,在释放早期视图控制器之前,它都会调用它们的视图外观方法。

我也有同样的问题。我再次创建了 navigationController,而不是重用旧的(我发布了它)。

谢谢,

As you said

Whenever I log out, I reset the navigationController's viewControllers
array to just the single Splash screen.

This indicates that you are setting navigationController's viewControllers again not the NavigationController itself.

It happens because whenever we put new viewcontroller's array in navigation stack, before releasing earlier viewcontroller it calls their view appearance methods.

I had the same problem. I created the navigationController again rather than reusing the old one(I released it).

Thanks,

醉南桥 2024-12-22 06:16:56

我不确定为什么会发生这种情况,但我认为最好在导航控制器上调用 popToRootViewController:NO 来重置它,而不是手动修改它的 viewControllers 数组。

尝试一下,看看是否仍然有问题。

I'm not sure why this is happening, but I think it would be better to call popToRootViewController:NO on the navigation controller to reset it rather than manually modifying it's viewControllers array.

Try that and see if it still has a problem.

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