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
Jean Philippeaux
4,259 Pointscourse "Build a Simple iPhone App" , step 5, "Animate this", Code Challenge # 1 : Image Based Animation
i'm totally blocked on the first question :
Assume you have images named 'Robot1.png','Robot2.png','Robot3.png','Robot4.png', create an array of UIImage objects called 'robotImages'.
Here's my code :
UIImage *image = [UIImage imageNamed:@"robot.png"]; UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; NSArray *robotImages = [NSArray alloc]; robotImages = [ initWithObjects: [UIImage imageNamed:@"Robot1"], [UIImage imageNamed:@"Robot2"], [UIImage imageNamed:@"Robot3"], [UIImage imageNamed:@"Robot4"], nil];
The compiler is saying that "Make sure you create an NSArray named 'robotImages' with instances of UIImage objects."
Any clue about what have i've made incorrectly ?
1 Answer
Jean Philippeaux
4,259 Pointsi've found the solution. Here's my code :
UIImage *image = [UIImage imageNamed:@"robot.png"]; UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
NSArray *robotImages = [[NSArray alloc] initWithObjects: [UIImage imageNamed:@"Robot1"], [UIImage imageNamed:@"Robot2"], [UIImage imageNamed:@"Robot3"], [UIImage imageNamed:@"Robot4"], nil];
everything worked fine !!
Brenden Konnagan
16,858 PointsBrenden Konnagan
16,858 PointsYou are very close...
To create the NSArray you are calling the alloc but adding a ; and missing a open bracket... try something like this: NSArray *robotImages = [[NSArray alloc] initWithObjects:@"Robot1.png", @"Robot2.png", @"Robot3.png", Robot4.png", nil];