Suraj K Thomas
Suraj K Thomas

Reputation: 5883

how to know if textfield value changd while data entered from a button ios

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?

Upvotes: 2

Views: 234

Answers (1)

Mihir Mehta
Mihir Mehta

Reputation: 13833

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
        }
}

Upvotes: 2

Related Questions