viewWillAppear 和 UIApplicationDidBecomeActiveNotification
当应用程序变为活动状态时,我使用 UIApplicationDidBecomeActiveNotification 刷新我的表格视图。我的问题是,在我的 ViewWillAppear 中,我还调用了一个方法来刷新该表的数据。
这导致表在应用程序启动时刷新两次。当应用程序最初启动时,如何才能让其中一个不触发?刷新表需要对网络和本地数据进行一些密集处理。所以我真的希望只执行一次此操作。
谢谢。
I am using the UIApplicationDidBecomeActiveNotification to refresh my tableview when the app becomes active. My problem is that in my ViewWillAppear, I am also calling a method to refresh this table's data.
This is causing the table to be refreshed twice upon application launch. How can I get one of them not to fire when the app is initially launched? Refreshing the table has some intensive processing of network and local data.. so I would really like o only perform this action once.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要使用UIApplicationWillEnterForegroundNotification而不是UIApplicationDidBecomeActiveNotification。
后者会在您的应用程序每次激活时发布(首次启动、通话/短信中断后返回应用程序等)。但前者仅在从后台唤醒的情况下发布。请注意,在这种情况下,viewWillAppear 不会被调用(乍一看应该是这样)。
You need to use UIApplicationWillEnterForegroundNotification instead of UIApplicationDidBecomeActiveNotification.
The latter is posted every time your app becomes active (initial launch, back to app after call/sms interruption, etc.). But the former is posted only in case of wake up from background. Note that in this case viewWillAppear is not called (as it should seems to be at the first sight).
一种方法是使用一个标志,您可以在
didFinishLaunching
中设置该标志,因为每次启动仅执行一次。One way to do it would be with a flag, that you can set up in
didFinishLaunching
, since that is only executed once per launch.