モノタッチ
アプリがフォアグラウンドに戻ったとき、これを知るためにアクティブになる ViewController が必要です。
ビューが前面に表示されたことを判断するために使用できるイベントまたはオーバーライドはありますか。
「WillEnterForegroundNotification」は見つかりましたが、文字列であるため、どのように使用されているかわかりません。
モノタッチ
アプリがフォアグラウンドに戻ったとき、これを知るためにアクティブになる ViewController が必要です。
ビューが前面に表示されたことを判断するために使用できるイベントまたはオーバーライドはありますか。
「WillEnterForegroundNotification」は見つかりましたが、文字列であるため、どのように使用されているかわかりません。
私はこれを見つけました:
これを ViewController の CTOR に入れます。
NSNotificationCenter.DefaultCenter.AddObserver (UIApplication.WillEnterForegroundNotification,
EnterForeground);
次に、このメソッドを作成して、View Controller でイベントを処理します。
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);
}