durazno durazno - 8 months ago 54
iOS Question

Why is my if statement not being called?

I'm using if statements in

so I can populate cells with the right images.

if ([object objectForKey:@"type"] == [NSNumber numberWithInt:0]) {

self.cell.typeImage.image = [UIImage imageNamed:@"type1"];

else if ([object objectForKey:@"type"] == [NSNumber numberWithInt:1]) {

self.cell.artTypeImage.image = [UIImage imageNamed:@"type2"];

else if ([object objectForKey:@"type"] == [NSNumber numberWithInt:2]) {

self.cell.artTypeImage.image = [UIImage imageNamed:@"type3"];

To clarify, I do get a value for
[object objectForKey:@"type"]
, as it does not return nil.


You compare two NSNumbers with isEqualToNumber:, not ==.

Additionally modifying the NSNumbers to have [NSNumber intValue] will allow == to work.

You need to modify each of your if statements and it should work.