开发者

How do you register for UIApplicationWillEnterForegroundNotification in MonoTouch

开发者 https://www.devze.com 2023-03-04 23:29 出处:网络
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

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.

How do you do this in MonoTouch? Or does anyone know an alt开发者_运维问答ernate way of ensuring that the screen is always kept up to date, even when returning from the background?


You could try something along the lines of:

//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!

0

精彩评论

暂无评论...
验证码 换一张
取 消