Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mandude

macrumors member
Original poster
Nov 19, 2009
64
0
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;
}
}

........
 
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.
 
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?
 
Uhhm, probably, the pretty light blue circular text bubbles that I can tab along with that tell me what to type :D
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 *).
 
I'm still torn though, I like the look of the parentheses :p
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.