Notifications Monotouch:控制器被带到前台-通知?
单触式 当一个应用程序被带回到前台时,我需要激活的ViewController来了解这一点 是否有一个事件或覆盖我可以用来确定该视图被带到前台 我确实找到了“WillEnterForegroundNotification”,但它是一个字符串,所以不确定它是如何使用的。我找到了以下内容: 将其放入ViewController的CTOR中:Notifications Monotouch:控制器被带到前台-通知?,notifications,xamarin.ios,foreground,Notifications,Xamarin.ios,Foreground,单触式 当一个应用程序被带回到前台时,我需要激活的ViewController来了解这一点 是否有一个事件或覆盖我可以用来确定该视图被带到前台 我确实找到了“WillEnterForegroundNotification”,但它是一个字符串,所以不确定它是如何使用的。我找到了以下内容: 将其放入ViewController的CTOR中: NSNotificationCenter.DefaultCenter.AddObserver (UIApplication.WillEnterForegroun
NSNotificationCenter.DefaultCenter.AddObserver (UIApplication.WillEnterForegroundNotification,
EnterForeground);
然后创建此方法来处理视图控制器中的事件
void EnterForeground (NSNotification notification)
{
Console.WriteLine("EnterForeground: " + notification.Name);
}
NSObject _didBecomeActiveNotification;
.
.
.
// and in constructor
_didBecomeActiveNotification = UIApplication.Notifications.ObserveDidBecomeActive((sender, args) => {
SetRightBarButtonState();
});
注意:当你的应用程序被带到前台时,UIApplicationLegate将首先引发此问题,这是一个清除登录详细信息和安全相关检查的好地方
public override void WillEnterForeground (UIApplication application)
在我的MonoTouch应用程序中,我有一个“添加”按钮,一旦点击该按钮,就会在一天的剩余时间里被禁用。要在应用程序处于活动状态时检查并启用按钮,请在ViewController的构造函数中监视应用程序.Notifications.ObservedBecomeActive
void EnterForeground (NSNotification notification)
{
Console.WriteLine("EnterForeground: " + notification.Name);
}
NSObject _didBecomeActiveNotification;
.
.
.
// and in constructor
_didBecomeActiveNotification = UIApplication.Notifications.ObserveDidBecomeActive((sender, args) => {
SetRightBarButtonState();
});
然后,我通过重写ViewController中的Dispose
方法
protected override void Dispose (bool disposing) {
if (disposing) {
_didBecomeActiveNotification.Dispose();
}
base.Dispose (disposing);
}