Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Nov 11, 2008, 04:58 PM   #1
ErikMadsen
macrumors newbie
 
Join Date: Feb 2008
Stupid Question. String values

I'm new to C/ObjC and am wondering why this statement is always true when I known darn well there's no text in the UITextFields referenced...

Code:
if(txtEmail.text != @"" && txtPassword.text != @""){
...
}
Many thanks. I'll go back to my corner and put my dunce cap back on until an answer arrives.
ErikMadsen is offline   0 Reply With Quote
Old Nov 11, 2008, 05:44 PM   #2
AussieSusan
macrumors member
 
Join Date: May 2006
Location: Melbourne, Australia
Objective-C strings are actually an instance of the NSString class - even the @"xxx" literals. Therefore what you are comparing is the addresses of the class instances and so both sides of each '!=' will always be different and so the '!=' will always 'true'.

What you want is something like (of the top of my head):
if( NO == [txtEmail.text isEqualTo:@""] && NO == [txtPassword.text isEqualTo:@""])

An alternative is:
if(* NSOrderedSame != [txtEmail.text compare:@""].........

(I suggest you look up the isEqualTo: and compare: functions to get the syntax right - I'm just going form memory).

Susan
AussieSusan is offline   0 Reply With Quote
Old Nov 11, 2008, 05:53 PM   #3
ErikMadsen
Thread Starter
macrumors newbie
 
Join Date: Feb 2008
Many thanks, Susan! *removes dunce cap and returns to desk*

Code:
if(![txtEmail.text isEqualToString:@""] && ![txtPassword.text isEqualToString:@""]){
[btnLogin setEnabled:YES];
}



Quote:
Originally Posted by AussieSusan View Post
Objective-C strings are actually an instance of the NSString class - even the @"xxx" literals. Therefore what you are comparing is the addresses of the class instances and so both sides of each '!=' will always be different and so the '!=' will always 'true'.

What you want is something like (of the top of my head):
if( NO == [txtEmail.text isEqualTo:@""] && NO == [txtPassword.text isEqualTo:@""])

An alternative is:
if(* NSOrderedSame != [txtEmail.text compare:@""].........

(I suggest you look up the isEqualTo: and compare: functions to get the syntax right - I'm just going form memory).

Susan
ErikMadsen is offline   0 Reply With Quote
Old Nov 11, 2008, 09:59 PM   #4
PhoneyDeveloper
macrumors 68020
 
PhoneyDeveloper's Avatar
 
Join Date: Sep 2008
isEqualTo: doesn't exist on the phone. Use isEqualToString: Even down unda.
PhoneyDeveloper is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
NSMutable Array, custom object losing string values AZWolf7 iPhone/iPad Programming 2 Oct 24, 2010 10:46 AM
iWork Numbers: Finding a string value based on a string ert3 Mac Applications and Mac App Store 6 Jul 19, 2010 09:43 AM
adding a string value to an NSTableView Chirone Mac Programming 4 Jun 19, 2009 09:34 AM
function takes string parameter and returns string value vidyareef iPhone/iPad Programming 3 Jan 21, 2009 04:50 PM
Ask a Stupid Question, Get a Stupid Answer Perceptes Community 12 May 7, 2003 08:29 AM


All times are GMT -5. The time now is 10:06 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

Privacy / DMCA contact / Affiliate and FTC Disclosure
Copyright 2002-2013, MacRumors.com, LLC