PDA

View Full Version : If Else, statement not working properly.




jjgraz
Apr 18, 2009, 10:35 PM
Any Ideas why my If Else Statement is not working? If I change the statment to read, if 1 == 1, it works fine. I'm sure alabel.status is bringing 50,(the debugger shows its returning 50). But alabel.status for some reason is not equal to @"50".....the same is true if i Return a word and not a number. Thank you. Code below.

if (alabel.status == @"50") {

UIImage *image = [UIImage imageNamed:@"image1.png"];
cell.image = image;

}

else {
UIImage *image = [UIImage imageNamed:@"image2.png"];
cell.image = image;

}


Thank you.



danmwall
Apr 18, 2009, 10:53 PM
I'm assuming alabel.status is a string. In order to compare strings, you have to use the isEqualToString command. It will look something like this:

if ([[NSString stringWithFormat:alabel.status] isEqualToString: @"50"]) {
UIImage *image = [UIImage imageNamed:@"image1.png"];
cell.image = image;

}

else {
UIImage *image = [UIImage imageNamed:@"image2.png"];
cell.image = image;

}

Hopefully that will take care of it for you!

jjgraz
Apr 19, 2009, 01:10 PM
that works great. Thank you very much.

chrmjenkins
Apr 19, 2009, 01:13 PM
This is a common mistake in a lot of programming languages :D

Just remember to ask yourself if the statement is comparing the actual data, or the pointer to the data.

CocoaPuffs
Apr 19, 2009, 04:22 PM
Apple to apple.