Compare UITextField Input to String (iPhone Development)

115

When dealing with user form, I was looking for the best way to form check. Coming from a web background, I’m used to doing it with javascript/ajax requests. In an if elseif statement that activate a button with all input field are not !== “”

To access the inputed iphone text from a uitext field:

myUITextField.text

To compare that input text to a string

[myUITextField.text isEqualToString:@"This String"]

I’m starting to fall in love with apples objective-c in the xcode environment, Apple got it right.

When the the form checking is complete we will post the code.



2 comments ↓

If you found this post useful click the share this button. Contribute below by adding a comment, no registration is required.

  • Compare UITextField Input to String (iPhone Development) | Design … | IPhoneMate says on 08.25.09 at 3:51 pm comment #1

    [...] rest is here: Compare UITextField Input to String (iPhone Development) | Design … Share and [...]

  • Stan says on 02.07.10 at 5:23 am comment #2

    That is a beautiful thing. The Apple doc for UITextField states that the default value for textField.text is nil, but validating against that can be a nightmare if you’re trying to do it in real-time against ‘Editing Changed’ events. This little method irons out all the ==nil, ==”", ==@”", comparisons very nicely.

Leave a Comment