PDA

View Full Version : Checking if text exists in UITextView




UberMonjie
Mar 5, 2009, 01:54 PM
if ([newMessageEntry text] != @"") {


No worky! The condition always comes back true, regardless of if I type anything into newMessageEntry textview.

How can I check to see if newMessageEntry actually had some text entered?

Thanks!



dejo
Mar 5, 2009, 02:25 PM
Compare against the length property of the text string. If it's == 0, there's no text.

UberMonjie
Mar 5, 2009, 02:57 PM
That did it, thanks!

dejo
Mar 5, 2009, 10:29 PM
That did it, thanks!
Something even better I found: UITextView has a "hasText" instance method. So,
if ([newMessageEntry hasText]) {
should do the trick.