2011-03-31 9 views
4

MonoTouchモノタック:コントローラがフォアグラウンドに持ち込まれました - 通知?

アプリがフォアグラウンドに戻されるとき、私はこのことを知るためにアクティブになるViewControllerが必要です。

ビューがフォアグラウンドにされたと判断するために使用できるイベントまたはオーバーライドはありますか。

私は "WillEnterForegroundNotification"を見つけましたが、それは文字列なので、その使い方がわかりません。

答えて

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) 
0

私のMonoTouchアプリには、一度タップされた「追加」ボタンが残りの日は無効になっています。アプリがアクティブになったときにボタンをチェックして有効にするには、ViewControllerのコンストラクタでUIApplication.Notifications.ObserveDidBecomeActiveを監視します。

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

そしてIは

protected override void Dispose (bool disposing) { 
    if (disposing) { 
     _didBecomeActiveNotification.Dispose(); 
    } 
    base.Dispose (disposing); 
} 
介しのViewControllerで Disposeメソッドをオーバーライド
関連する問題