views:

45

answers:

2

Here's the code:

- (IBAction) charlieImputText:(id)sender {
    //getting value from text field when entered
    charlieImputSelf = [sender stringValue];

    if (charlieImputSelf != @"") {
        (send field if not empty)
    }
}    

This sends it even when the field is empty; therefore, this does not work as I want it to.

Sorry to be so vague... :D

Any ideas?? Elijah

+2  A: 

You really need to read the docs. You're asking a lot of questions that would be answered very simply from that.

[textField.text length] > 0 is the way to check if its empty.

Joshua Weinberg
+1  A: 

Joshua has the right answer in the narrow case, but generally, you can't compare string objects using the == or != operators. You must use -isEqual: or -isEqualToString: This is because charlieImputSelf and @"" are actually pointers to objects. Although the two sequences of characters may be the same, they need not point at the same location in memory.

JeremyP
So if you would want to check if the value of the text field was equal to `Boo`, you'd have to use `if ([textField.text isEqualToString:@"Boo"])` instead of `if (textField.text == @"Boo")`
Douwe Maan
Yes (it's annoying I can't just enter 'yes' in this text box)
JeremyP
haha :D (waisting space....)
Elijah W.