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 trialGregg Mojica
11,506 PointsUiImage Code Challenge
Hi Guys, Stuck on this question:
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
Stephen Whitfield
16,771 Pointsor you could stick it all on one line. like this:
UIImageView *myImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pizza_slice"]];
Gregg Mojica
11,506 PointsFigured it out! UIImage *images; [UIImage imageNamed: @"pizza_slice"]; UIImageView *myView = [[UIImageView alloc] init]; myView.image = images;
R Brewster
15,328 PointsThis seems to work
[UIImage imageNamed:@"pizza_slice"]; UIImageView *pizzaImage = [[UIImageView alloc] init]; pizzaImage.image = [UIImage imageNamed:@"pizza_slice"];
Stephen Whitfield
16,771 PointsIt 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
15,328 PointsGood point. Thanks Stephen.