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

UiImage Code Challenge

Hi Guys, Stuck on this question:

Link http://teamtreehouse.com/library/ios-development/build-a-selfdestructing-message-iphone-app/further-enhancing-the-user-interface-and-experience/customizing-table-view-cell-disclosure-indicators-2

Question Next we need a UIImageView to display the pizza slice UIImage. Create a UIImageView variable and set its 'image' property to the UIImage variable you just created.

My Code [UIImage imageNamed: @"pizza_slice"]; UIImageView *myView = [[UIImageView alloc] init];

Not sure where to go from here...

Thanks!

4 Answers

or you could stick it all on one line. like this:

            UIImageView *myImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pizza_slice"]]; 

Figured it out! UIImage *images; [UIImage imageNamed: @"pizza_slice"]; UIImageView *myView = [[UIImageView alloc] init]; myView.image = images;

R Brewster
R Brewster
15,328 Points

This seems to work

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

It works, but you're breaking the DRY (Don't Repeat Yourself) principle. The UIImage declaration in that first line is not needed, as you have already assigned that image to your UIImageView in the last line. Take that out and you'll be fine.

R Brewster
R Brewster
15,328 Points

Good point. Thanks Stephen.