Monotouch: controller brought to the forefront - notice?

Monoouch

When the application returns to the forefront, I need a ViewController that becomes active to find out.

Is there an event or override that I can use to determine that the view has been brought to the fore.

I found "WillEnterForegroundNotification", but this is a string, so I don’t know how it is used.

+4
source share
2 answers

I found this:

Put this in the CTOR ViewController:

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

Create this method to handle the event in the view controller.

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

Note. When your application is brought to the forefront, UIApplicationDelegate will get this first, this is a good place to clean things like login data and security checks.

 public override void WillEnterForeground (UIApplication application) 
+8
source

In my MonoTouch application, I have an β€œadd” button, which, after disconnecting, is disabled for the rest of the day. To check and activate the button when the application becomes active, I track the UIApplication.Notifications.ObserveDidBecomeActive in the constructor for the ViewController.

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

Then I override the Dispose method in ViewController via

 protected override void Dispose (bool disposing) { if (disposing) { _didBecomeActiveNotification.Dispose(); } base.Dispose (disposing); } 
0
source

Source: https://habr.com/ru/post/1345997/


All Articles