I tried this same question on some other boards and its up to like 70 views and no replies
Okay. So I'm trying to make a simple practice application with Xcode and Interface Builder 3. As part, I want the user to enter text into a field and press a button which will check if the input matches something, and if it does, display correct. So here is the code that will do that when the button is pressed:
Now, after trying this with the rest of the app, it gives me incorrect for everything I put in, including the right answer, "fourthdimension." I have no idea why it's doing this. To test it, I tried the whole same concept with integers:
This, for some reason, works. When I input 5, it gives me 1. For everything else, 0. This is correct.
I think it might somehow be space thats causing an entered string not to equal @"fourthdimension". Could it be taking all the rest of the space in the text field? Is there any type of string class that ignores spaces or something? Or the problem could be something else...
I didn't exactly know where to put this question on the forums, so I just put it here. Hope somebody can help.
Okay. So I'm trying to make a simple practice application with Xcode and Interface Builder 3. As part, I want the user to enter text into a field and press a button which will check if the input matches something, and if it does, display correct. So here is the code that will do that when the button is pressed:
Code:
- (IBAction)checkPass:(id)sender {
if ([textField stringValue] == @"fourthdimension") {
[infoLabel setStringValue:@"Your password was correct!"];
} else {
[infoLabel setStringValue:@"Your password was incorrect!"];
}
}
Now, after trying this with the rest of the app, it gives me incorrect for everything I put in, including the right answer, "fourthdimension." I have no idea why it's doing this. To test it, I tried the whole same concept with integers:
Code:
- (IBAction)checkPass:(id)sender {
if ([textField intValue] == 5) {
[infoLabel setIntValue:1];
} else {
[infoLabel setIntValue:0];
}
}
This, for some reason, works. When I input 5, it gives me 1. For everything else, 0. This is correct.
I think it might somehow be space thats causing an entered string not to equal @"fourthdimension". Could it be taking all the rest of the space in the text field? Is there any type of string class that ignores spaces or something? Or the problem could be something else...
I didn't exactly know where to put this question on the forums, so I just put it here. Hope somebody can help.