Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Implementing Designs for iPhone Customizing Table View Controllers Customizing Table View Cell Disclosure Indicators

Further Enhancing the User Interface | Customizing Table View Cell Disclosure Indicators | Challenges 2 & 3

I don't know what I've done or why it worked...

I passed the first two challenges with the following code:

UIImage *imageNamed = [UIImage imageNamed:@"pizza_slice"];
    cell.imageView.image = [UIImage imageNamed:@"pizza_slice"];

But then I got stuck on the third challenge and began hunting the forums for a solution, coming across this:

UIImage *imageNamed = [UIImage imageNamed:@"pizza_slice"];
    UIImageView *pizzaImage = [[UIImageView alloc]init];
    pizzaImage.image = [UIImage imageNamed:@"pizza_slice"];

I get it now, the "create" in the "...Create a UIImageView variable and set its 'image' property to the UIImage variable you just created." directions means that I've got to allocate and initialize a new UIImageView. Making the third challenge a breeze:

UIImage *imageNamed = [UIImage imageNamed:@"pizza_slice"];
    UIImageView *pizzaImage = [[UIImageView alloc]init];
    pizzaImage.image = [UIImage imageNamed:@"pizza_slice"];
    cell.accessoryView = pizzaImage;

What I don't understand is why my first response to the second challenge worked.

  • Can the imageView property of the cell be accessed and assigned an image?
  • If so, can the accessoryView property of the cell be assigned the newly assigned imageView property?
  • Why or why not?

Thanks!

3 Answers

Soojin Ro
Soojin Ro
13,331 Points

In your first answer, you declared "imageNamed" but never used it. It should look like

UIImage *pizzaImage = [UIImage imageNamed:@"pizza_slice"];
cell.imageView.image = pizzaImage;

For your question, inside the UIImageView object, there is a property called 'image' which is a UIImage object. But inside the accessoryView, there is no imageView property so you cannot assign one

Sorry Drew,

But I couldn't pass the third part of the challenge with the line you suggested:

cell.accessoryView = pizzaImage;

However I found this thread: https://teamtreehouse.com/forum/stuck-on-ios7-design-badge-customizing-table-view-controllers-badge

..which had this helpful line of code:

cell.accessoryView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"pizza_slice"]];

Hopefully that clears up any 'confusion' the code posted in this thread might have caused...

Thanks Soojin! The statement "inside the UIImageView object, there is a property called 'image' which is a UIImage object. But inside the accessoryView, there is no imageView property so you cannot assign one" is what really helped.