Help with UITextField plz

Discussion in 'iOS Programming' started by mandude, Dec 21, 2009.

  1. mandude macrumors member

    Joined:
    Nov 19, 2009
    #1
    k so i have a UITextField just chilling here. now i want it to be that if the user types in a single word or phrase, and pressed the done key, then a UILabel will appear. heres what i have so far but its not working so good:


    h file:

    Code:
    
    @interface........ {
    UITextField *textField;
    UILabel *label;
    }
    @property (nonatomic, retain) IBOutlet UILabel *label;
    @property (nonatomic, retain) IBOutlet UITextField *textField;
    -(IBAction)textFieldDoneEditing:(id)sender;
    @end
    

    m. file:

    Code:
    
    @synthesize textField;
    @synthesize label;
    
    
    -(IBAction)textFieldDoneEditing:(id)sender {
    [sender resignFirstResponder];
    if (textField.text == @"Hello There") {
    label.hidden = NO;
    }
    }
    
    ........
    
    
     
  2. MythicFrost macrumors 68040

    MythicFrost

    Joined:
    Mar 11, 2009
    Location:
    Australia
  3. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #3
    Please elaborate. Vague descriptions of issues aren't going to provide enough basis to make a diagnosis.

    Either'll work. label.hidden takes advantage of Objective-C 2.0's dot notation ability.

    P.S. What's with the extraneous parentheses around NO?
     
  4. MythicFrost macrumors 68040

    MythicFrost

    Joined:
    Mar 11, 2009
    Location:
    Australia
    #4
    Oh I see, and I put them there because that's what shows up in XCODE when it shows me what to type, and I like them lol.
     
  5. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #5
    You can't compare strings like this

    Code:
    if (textField.text == @"Hello There")
    you need to do it this way

    Code:
    if ([textField.text isEqualToString:@"Hello There"])
    Using == compares the pointers for equality and doesn't compare the contents of the strings.

    Also, I'm not clear how this action method is supposed to be called. First, is it called? Why aren't you implementing the UITextFieldDelegate protocol?
     
  6. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    Explain further. Are you referring to Code Sense?
     
  7. MythicFrost macrumors 68040

    MythicFrost

    Joined:
    Mar 11, 2009
    Location:
    Australia
    #7
    Uhhm, probably, the pretty light blue circular text bubbles that I can tab along with that tell me what to type :D
     
  8. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #8
    You're expected to replace the entire bubble with a value. So (BOOL) would be replaced with NO (or YES). The reason for the parentheses is that is how Objective-C refers to the datatype, as in (BOOL) or (id) or (UILabel *).
     
  9. MythicFrost macrumors 68040

    MythicFrost

    Joined:
    Mar 11, 2009
    Location:
    Australia
    #9
    Alright, good to know, thanks. I'm still torn though, I like the look of the parentheses :p
     
  10. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #10
    If you like the look, go ahead and leave them; they don't really hurt anything. Just realize that they will probably cause confusion if most anybody else looks at your code, since they are not used in the average coding style.
     
  11. MythicFrost macrumors 68040

    MythicFrost

    Joined:
    Mar 11, 2009
    Location:
    Australia
  12. mandude thread starter macrumors member

    Joined:
    Nov 19, 2009
    #12
    I have no idea but I'd like to just know how yto get this to work
     
  13. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #13
    Well, we can't really help you get it working if we don't have answers to the questions we've asked you. In other words, before we can help you, you need to help us.
     

Share This Page