samouray
samouray

Reputation: 578

Why is my UIImageView not showing in my TableViewController Cell?

I have a TableViewController that have a cell which I customized, I added a label and a UIImageView. My Image does not show up, I changed the background color of the UIImageView object to see if I am not just having a layout problem, and it shows the color I selected, so It is indeed not a layout problem. My cellForRowAtIndexPath code is :

UITableViewCell *cell = [self.myTableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];



    UIImageView *fromImageVIew = (UIImageView *)[cell viewWithTag:1];

    UIImage *fromImage = [UIImage imageNamed:@"MyImag.jpg"];
    fromImageVIew = [[UIImageView alloc] initWithImage: fromImage];

When I NSLog the content of fromImageVIew I get an Object so I am sure it is not Nil.

Ps: I checked in my storyBoard if I have the correct Tag number in my UIImageView and it is indeed 1.

Any help ?

Upvotes: 0

Views: 58

Answers (1)

Ben Zotto
Ben Zotto

Reputation: 71008

You're dropping the reference to the imageView that's inside the cell when you allocate a brand new one. At that point fromImageView now points to the new one you just allocated that doesn't exist in any view hierarchy yet.

If you know for sure there is an imageView in your cell, then you can just set the loaded image into the existing view:

UIImage *fromImage = [UIImage imageNamed:@"MyImag.jpg"];
fromImageVIew.image = fromImage;    

Upvotes: 2

Related Questions