views:

322

answers:

2

Hi.

I have a UITable View with a textfield that is editable right on the view (like Phone in contacts, etc.). I want to enable/disable my save button conditional up text being present in this field. So, I want the button to start out as disabled (for a new record) and then, as soon as I type the first letter into my text field, I want the button enabled. If I delete again back to zero, I would like the button disabled. You get the point.

Now, for doing this I need some way to detect the text being inputed while the user writes it (and when he finishes editing).

Does anybody know how to do this?

Thanks a lot. Still noob...

+1  A: 

Try this: (from the Apple documentation for UITextInputTraits)

enablesReturnKeyAutomatically

A Boolean value indicating whether the return key is automatically enabled when text is entered by the user.

@property(nonatomic) BOOL enablesReturnKeyAutomatically

Discussion

The default value for this property is NO. If you set it to YES, the keyboard disables the return key when the text entry area contains no text. As soon as the user enters any text, the return key is automatically enabled.

Jasarien
It wasn't the return key on the keyboard, it was a button in the navigation Bar.I figured out how to do what I want using- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)stringbut you and jlehr were faster than me, and I couldn't sey that the problem was fixed.Thanks a lot anyway.
camilo
A: 

Have your view controller adopt the UITextFieldDelegate protocol, and then implement a couple of the protocol's methods:

– textFieldDidBeginEditing:
– textFieldDidEndEditing:

Also, be sure to set the text field's delegate property to point to your view controller. The text field will then automatically send these messages to the controller when editing session begins and ends.

jlehr
It wasn't that, I needed to use - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {And then test if the text length was bigger than 0. Anyway thanks a lot.
camilo
@camilo Please consider writing up your findings and post it as your answer. The SO FAQ explicitly permits answering your own questions.
Frank Shearar
Usually I write my findings as a comment, but I confess I didn't read the FAQ. But it is logical when you think about it. From now on I'll do it like you said. Greetings.
camilo