Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement ShouldChangeCharacters in Monotouch?

I have a UITextField where I want to change the characters using ShouldChangeCharacters delegate method. But when I use the textField obj, it says that does not match with UITextFieldChange... How should I do it in Monotouch?

like image 834
Rahul Raj Avatar asked Dec 28 '22 02:12

Rahul Raj


1 Answers

Here is an example of forcing all caps:

    textField.ShouldChangeCharacters = (textField, range, replacementString) => 
    {
        using (NSString original = new NSString(textField.Text), replace = new NSString(replacementString.ToUpper()))
        {
            textField.Text = original.Replace (range, replace);
        }
        return false;
    };

I think it should be what you need. I tend to use Lambda expressions always, that way you don't need to even know the delegate type, parameters types, etc. I let C# type inference do the work.

like image 136
jonathanpeppers Avatar answered Jan 26 '23 00:01

jonathanpeppers