Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.