viewDidAppear不会在应用程序进入前台后再次触发 [英] viewDidAppear not firing ever again after app enters foreground

查看:520
本文介绍了viewDidAppear不会在应用程序进入前台后再次触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的iPhone应用程序代码中跟踪了一个问题,viewDidAppear方法不总是触发。当您启动应用程序时,事件会按预期触发。但是,如果我关闭应用程序使用一个能够多任务和重新打开的手机。我的viewDidAppear事件不再触发。

I have traced a problem in my iPhone app code to the viewDidAppear method not always firing. When you start the app the event fires as expected. However if I close the app using a phone capable of multitasking and reopen in. My viewDidAppear events no longer fire.

我的视图从Nibs加载,我使用viewDidUnload清理(释放和所有出口)。我的视图嵌套在侧面和标签栏,然后导航控制器。我看起来像事件没有正确连接正确时,nibs重新加载。任何想法,我做错了/缺少,我怎么可以解决这个问题?

My views are loaded from Nibs and I use viewDidUnload to clean up (release and nil all outlets). My views are nested in side and tab bar then navigation controllers. I looks like the events aren't wired up properly when the nibs reload. Any idea on what I'm doing wrong/missing and how I can fix this?

提前感谢。

UPDATE 当应用程序第一次进入前台时触发。我的意思是事件不再发生。

UPDATE I do not mean the event is not fired when the app first comes into the foreground. I mean the event never fires again. Even when changing between tabs or moving though the navigation views.

示例:

- (void)viewDidAppear:(BOOL)animated {
   [super viewDidAppear:animated];
   NSLog(@"viewDidAppear called");
}

此代码放置在两个视图中,每个视图位于不同的选项卡上。每次我在标签viewDidAppear called之间切换时写入日志。当我关闭并重新打开应用程序,并在标签之间切换不再发生。其他按钮事件正常发生。

This code is placed in two views, each on different tabs. Each time I swap between tabs "viewDidAppear called" is written to the log. When I close and reopen the app and swap between tabs this no longer happens. Other button events fire normally.

推荐答案

找到它。

虽然不是最新的编程我是iPhone开发的新手。在研究这个问题时,我发现不建议手动调用 viewWillAppear viewWillDisappear 方法。

While not new to programming I am new to iPhone development. On researching this problem I found it was not recommended to call the viewWillAppear and viewWillDisappear methods manually.

我的 viewWillDisappear 方法将辞职任何键盘,如果显示,当我的应用程序进入后台加载启动画面准备好,进入前台(有一些逻辑,我需要做的是弄清楚用户在重新启动应用程序时显示什么,我可以在启动屏幕下执行此操作)。

My viewWillDisappear methods resign any keyboards if shown, when my app enters the background it loads a splash screen ready for when the app re-enters the foreground (there is some logic I need to do to work out what the user is shown on restarting the app and I can do this under the splash screen).

由于 viewWillDisappear 在应用程序进入后台时才会调用,以确保在启动屏幕上没有出现键盘我在 applicationDidEnterBackground 方法中调用 viewWillDisapper 。我想这也取消注册我的事件。

As viewWillDisappear is not called when the app goes into the background to make sure no keyboards appeared over my splash screen I was calling viewWillDisapper in the applicationDidEnterBackground method. I guess this also un-registers my events.

通过添加 viewWillAppear 到我的 applicationDidEnterForeground 方法,我的事件再次启动。经验教训,我将重构这个,所以我不手动调用这些事件。

By adding viewWillAppear to my applicationDidEnterForeground method my events started firing again. Lesson learned, I will refactor this so I don't call these events manually.

感谢您的帮助。

这篇关于viewDidAppear不会在应用程序进入前台后再次触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆