Search code examples
c#iosxamarin.iosperformselector

Using PerformSelector with @selector in MonoTouch


I am trying to convert the following iOS code into MonoTouch and cannot figure out the proper conversion for the @selector(removebar) code. Can anyone provide guidance about the best way to handle @selector (since I've come across that in other places as well):

- (void)keyboardWillShow:(NSNotification *)note {
[self performSelector:@selector(removeBar) withObject:nil afterDelay:0];
}

My C# code is:

NSNotificationCenter.DefaultCenter.AddObserver(UIKeyboard.WillShowNotification,
              notify => this.PerformSelector(...stuck...);

I am basically trying to hide the Prev/Next buttons that show on the keyboard.

Thanks in advance for any help.


Solution

  • NSNotificationCenter.DefaultCenter.AddObserver(UIKeyboard.WillShowNotification, removeBar);
    

    where removeBar is a method defined elsewhere.

    void removeBar (NSNotification notification)
    {
        //Do whatever you want here
    }
    

    Or, if you prefer using a lambda:

    NSNotificationCenter.DefaultCenter.AddObserver (UIKeyboard.WillShowNotification, 
                                                    notify => { 
                                                        /* Do your stuffs here */
                                                    });