Mike
Mike

Reputation: 1732

UiTextField events

When I create UITextField inside Interface Builder, I can access Events tab for it, which has events like Value changed, Touch cancel, Touch drag, etc. I can assign my own methods to every of those events. How can I do the same, when I create UITextField programmatically with alloc?

Upvotes: 12

Views: 14961

Answers (3)

Baryon Lee
Baryon Lee

Reputation: 1177

Instead of UIControlEventValueChanged, you should use UIControlEventEditingChanged:

[_titleTextField addTarget:self action:@selector(handleTitleValueChanged:) forControlEvents:UIControlEventEditingChanged];

Upvotes: 11

falconcreek
falconcreek

Reputation: 4170

Refer to Apple documentation for UIControl. After initializing your textField, call addTarget:action:forControlEvents:

example for the touch event ending an edit session

[textField addTarget:self action:@selector(handleTouchValueChanged:) forControlEvents: UIControlEventEditingDidEnd]

Upvotes: 14

hajikelist
hajikelist

Reputation: 1176

UIControlEventEditingChanged fires whenever user changes value [synchronous with typing or keyup] which could cause extra hits to your data handler routine, if you're saving values based on that event, expecting it to be some kind of final value from user input...

Upvotes: 3

Related Questions