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

jjgraz

macrumors regular
Original poster
Feb 13, 2009
103
0
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:mad:"image1.png"];
cell.image = image;

}

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

}


Thank you.
 

danmwall

macrumors newbie
Apr 13, 2009
17
0
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:mad:"image1.png"];
cell.image = image;

}

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

}

Hopefully that will take care of it for you!
 

chrmjenkins

macrumors 603
Oct 29, 2007
5,325
158
MD
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.