gpt4 book ai didi

iphone - 如何在 MonoTouch 中注册 UIApplicationWillEnterForegroundNotification

转载 作者:行者123 更新时间:2023-12-03 19:09:26 25 4
gpt4 key购买 nike

我有一个问题,当应用程序从后台返回时,UIView 的 ViewWillAppear 方法不会触发。这是一个问题,因为我的主应用程序屏幕显示从用户设置检索的值,如果用户在应用程序处于后台时更改了这些值,我需要刷新屏幕。我读到应该使用 NSNotificationCenter 注册 UIApplicationWillEnterForegroundNotification。

如何在 MonoTouch 中执行此操作?或者有人知道确保屏幕始终保持最新的替代方法,即使从后台返回时也是如此?

最佳答案

您可以尝试以下方法:

//Register for the notification somewhere in the app
NSNotificationCenter.DefaultCenter.AddObserver(UIApplication.WillEnterForegroundNotification, EnteredForeground);

//snip

void EnteredForeground (NSNotification notification)
{
// do your stuff here
}

请记住,从后台进入时,您需要对要更新的每个 View Controller 执行此操作!

关于iphone - 如何在 MonoTouch 中注册 UIApplicationWillEnterForegroundNotification,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5967232/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com