4

单触

当应用程序回到前台时,我需要激活的 ViewController 来了解这一点。

是否有一个事件或覆盖我可以用来确定视图被带到了前台。

我确实找到了“WillEnterForegroundNotification”,但它是一个字符串,所以不确定它是如何使用的。

4

2 回答 2

8

我找到了这个:

把它放在 ViewController 的 CTOR 中:

NSNotificationCenter.DefaultCenter.AddObserver (UIApplication.WillEnterForegroundNotification, 
    EnterForeground); 

然后创建此方法以处理视图控制器中的事件。

void EnterForeground (NSNotification notification)
{
    Console.WriteLine("EnterForeground: " + notification.Name); 
}

注意:当您的应用程序被带到前台时, UIApplicationDelegate 将首先引发此问题,这是清除登录详细信息和安全相关检查等内容的好地方。

public override void WillEnterForeground (UIApplication application)
于 2011-03-31T07:28:43.180 回答
0

在我的 MonoTouch 应用程序中,我有一个“添加”按钮,一旦点击它就会在一天的剩余时间里被禁用。为了在应用程序变为活动状态时检查并启用按钮,我UIApplication.Notifications.ObserveDidBecomeActive在 ViewController 的构造函数中进行了监控。

NSObject _didBecomeActiveNotification;
.
.
.
// and in constructor
_didBecomeActiveNotification = UIApplication.Notifications.ObserveDidBecomeActive((sender, args) => {
    SetRightBarButtonState();
});

然后我通过覆盖DisposeViewController 中的方法

protected override void Dispose (bool disposing) {
    if (disposing) {
        _didBecomeActiveNotification.Dispose();
    }
    base.Dispose (disposing);
}
于 2012-11-14T20:22:26.057 回答