你如何在 MonoTouch 中注册 UIApplicationWillEnterForegroundNotification [英] How do you register for UIApplicationWillEnterForegroundNotification in MonoTouch

查看:34
本文介绍了你如何在 MonoTouch 中注册 UIApplicationWillEnterForegroundNotification的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a problem that the ViewWillAppear method for a UIView does not fire when the application returns from the background. This is a problem, as my main application screen is showing values that are retrieved from the user settings, and if the user has changed these while the application was in the background I need to have the screen refreshed. I have read that one should register for the UIApplicationWillEnterForegroundNotification using NSNotificationCenter.

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

How do you do this in MonoTouch? Or does anyone know an alternate way of ensuring that the screen is always kept up to date, even when returning from the background?

推荐答案

您可以尝试以下方式:

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

//snip

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

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

Bear in mind you would need to do this for every view controller you'd like to update when enterting from the background!

这篇关于你如何在 MonoTouch 中注册 UIApplicationWillEnterForegroundNotification的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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