Forums
New posts
Articles
Product Reviews
Policies
FAQ
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Menu
Log in
Register
Install the app
Install
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
Cocoa programming issue
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Meds" data-source="post: 775503" data-attributes="member: 67584"><p>I tried this same question on some other boards and its up to like 70 views and no replies <img src="/mac_images/images/smilies/Straight-Faced.png" class="smilie" loading="lazy" alt=":|" title="Straight Faced :|" data-shortname=":|" /></p><p></p><p>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:</p><p></p><p>[CODE]- (IBAction)checkPass:(id)sender {</p><p></p><p> if ([textField stringValue] == @"fourthdimension") {</p><p> </p><p> [infoLabel setStringValue:@"Your password was correct!"];</p><p> </p><p> } else {</p><p> </p><p> [infoLabel setStringValue:@"Your password was incorrect!"];</p><p> </p><p> }</p><p> </p><p>}[/CODE]</p><p></p><p>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:</p><p></p><p>[CODE]- (IBAction)checkPass:(id)sender {</p><p></p><p> if ([textField intValue] == 5) {</p><p> </p><p> [infoLabel setIntValue:1];</p><p> </p><p> } else {</p><p> </p><p> [infoLabel setIntValue:0];</p><p> </p><p> }</p><p></p><p>}[/CODE]</p><p></p><p>This, for some reason, works. When I input 5, it gives me 1. For everything else, 0. This is correct. </p><p></p><p>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...</p><p></p><p>I didn't exactly know where to put this question on the forums, so I just put it here. Hope somebody can help.</p></blockquote><p></p>
[QUOTE="Meds, post: 775503, member: 67584"] 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: [CODE]- (IBAction)checkPass:(id)sender { if ([textField stringValue] == @"fourthdimension") { [infoLabel setStringValue:@"Your password was correct!"]; } else { [infoLabel setStringValue:@"Your password was incorrect!"]; } }[/CODE] 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]; } }[/CODE] 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. [/QUOTE]
Verification
Name this item. 🍎
Post reply
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
Cocoa programming issue
Top