Checking if text exists in UITextView

Discussion in 'iPhone/iPad Programming' started by UberMonjie, Mar 5, 2009.

  1. macrumors newbie

    Joined:
    Feb 11, 2009
    #1
    Code:
    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!
     
  2. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    Compare against the length property of the text string. If it's == 0, there's no text.
     
  3. thread starter macrumors newbie

    Joined:
    Feb 11, 2009
    #3
    Yep!

    That did it, thanks!
     
  4. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    Something even better I found: UITextView has a "hasText" instance method. So,
    Code:
    if ([newMessageEntry hasText]) {
    should do the trick.
     

Share This Page