Question

I have a static method in a separate class to handle UIKeyboard.WillHideNotification & UIKeyboard.WillShowNotification so that it can be used across the app.

I am adding the observer in a ViewController in the following way :-

NSNotificationCenter.DefaultCenter.AddObserver (UIKeyboard.WillHideNotification, KeyboardAppearanceUtilities.OnKeyboardNotification);

How can I get the observer object in the notification Action method which is declared in KeyboardAppearanceUtilities class as follows :-

public static void OnKeyboardNotification (NSNotification notification)
{

}

notification.Object is always null for obvious reason that I am not setting the object parameter in the AddObserver method.

Can someone guide me how to rearrange the code so that this notification handler can be used across the app and also gives me access to the observer?

Was it helpful?

Solution

Your code would be a lot nicer if you used the strongly typed notifications:

http://iosapi.xamarin.com/?link=M%3aMonoTouch.UIKit.UIKeyboard%2bNotifications.ObserveWillHide

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top