MonoTouch
当应用程序被恢复到前台时,我需要活动的ViewController知道这一点。
是否有可以使用的事件或覆盖来确定视图是否被带到前台。
我找到了“WillEnterForegroundNotification”,但它是一个字符串,所以不确定如何使用它。
MonoTouch
当应用程序被恢复到前台时,我需要活动的ViewController知道这一点。
是否有可以使用的事件或覆盖来确定视图是否被带到前台。
我找到了“WillEnterForegroundNotification”,但它是一个字符串,所以不确定如何使用它。
我发现了这个:
将以下内容放入 ViewController 的构造函数中:
NSNotificationCenter.DefaultCenter.AddObserver (UIApplication.WillEnterForegroundNotification,
EnterForeground);
void EnterForeground (NSNotification notification)
{
Console.WriteLine("EnterForeground: " + notification.Name);
}
public override void WillEnterForeground (UIApplication application)
UIApplication.Notifications.ObserveDidBecomeActive
。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);
}