-3

I'm using if statements in cellForRowAtIndexPath: 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.

Wyetro
  • 8,439
  • 9
  • 46
  • 64
durazno
  • 559
  • 2
  • 7
  • 25
  • 1
    An if statement is not getting "called" because it is not a function. As to why its *body* might not be *executed:* as Objective-C objects are pointers, `==` compares identity (pointer equality) rather than semantic equivalence. – The Paramagnetic Croissant Aug 28 '15 at 15:12

1 Answers1

1

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.

Wyetro
  • 8,439
  • 9
  • 46
  • 64