2

how can i know if a textfield value is changed while i'm entering data from some buttons rather than from keyboard .I have tried UITextfield delegate methods but it works only if i am tusing the keyboard.I am using different UIButtons to enter data on the textfield,so UITextfield delegates wont work here.Please share your thoughts on the approache's i should use here.Should i use NSNotification??but how to know textfield value changed on data entered from UIButton.

The references i have used are Listen to a value change of my text field

How to check text field input at real time?

Community
  • 1
  • 1
Suraj K Thomas
  • 5,773
  • 4
  • 52
  • 64
  • 1
    May be this tutorial can help you. http://www.techrepublic.com/blog/software-engineer/use-custom-keyboard-views-for-customized-text-field-input/ – NightFury May 29 '14 at 06:57

1 Answers1

2

You can add key-value observing on that particular UITextField

for Example

[myTextField addObserver:self forKeyPath:@"text" options:0 context:nil];

// then implement this method

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context 
{
        if([keyPath isEqualToString:@"text"] && [object isEqual:myTextField]) 
        {
            // here your logic on text change
        }
}
nikhil84
  • 3,235
  • 4
  • 22
  • 43
Mihir Mehta
  • 13,743
  • 3
  • 64
  • 88