Xavi Valero
Xavi Valero

Reputation: 2057

Keypress event in textfields

I have a situation where I need to have a "backspace" key press event inside a textfield. Is there a direct method to use this event, or do I have to implement the textfield delegate and apply some logics.

Upvotes: 0

Views: 441

Answers (1)

sElanthiraiyan
sElanthiraiyan

Reputation: 6268

You don't have to use a delegate essentially. You can set up a notification like below,

[[NSNotificationCenter defaultCenter] addObserver:self
          selector:@selector(handleTextFieldChanged:)
              name:UITextFieldTextDidChangeNotification
            object:searchTextField];

and you can handle the change by implementing handleTextFieldChanged.

This may help Detect backspace in UITextField

Upvotes: 1

Related Questions