你如何在MonoTouch中注册UIApplicationWillEnterForegroundNotification

Bru*_*ill 4 iphone xamarin.ios

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

你是如何在MonoTouch中做到这一点的?或者有没有人知道另一种确保屏幕始终保持最新的方法,即使从后台返回也是如此?

Luk*_*uke 7

您可以尝试以下方面的内容:

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

//snip

void EnteredForeground (NSNotification notification)
{
    // do your stuff here
}
Run Code Online (Sandbox Code Playgroud)

请记住,您需要为从后台进行娱乐时要更新的每个视图控制器执行此操作!