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