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
Paul Denlinger
3,292 PointsCan't create array of UIImage objects
Am trying to create an array for the Code Challenge in Image Based Animation, but am getting an error. The challenge is to: "Assume you have images named 'Robot1.png','Robot2.png','Robot3.png','Robot4.png', create an array of UIImage objects called 'robotImages'" The code I have entered is: UIImage *robotImages = [[NSArray alloc]initWithObjects:@"Robot1", @"Robot2", @"Robot3", @"Robot4", nil];
What am I doing wrong?
1 Answer
Stone Preston
42,016 Pointsyou need to instantiate an array not a UIImage
NSArray *robotImages = [[NSArray alloc]initWithObjects:@"Robot1", @"Robot2", @"Robot3", @"Robot4", nil];
Paul Denlinger
3,292 PointsPaul Denlinger
3,292 PointsOK, I made the change to: NSArray *robotImages = [[NSArray alloc]initWithObjects:@"Robot1", @"Robot2", @"Robot3", @"Robot4", nil];
But I get this message: Bummer! Make sure you create an NSArray named 'robotImages' with instances of UIImage objects.
Stone Preston
42,016 PointsStone Preston
42,016 Pointsok I was assuming you had already initialized the UIImages. If you havent, you can do it inside the array init like so
NSArray *robotImages = [[NSArray alloc]initWithObjects:[UIImage imageNamed:@"Robot1"], [UIImage imageNamed:@"Robot2"], nil];Paul Denlinger
3,292 PointsPaul Denlinger
3,292 PointsThank you, that worked.
For the next question: Set the animation images property of 'imageView' to 'robotImages'.
I wrote the following: self.imageView.animationImages = robotImages;
But got the response: Bummer! Make sure you create an NSArray named 'robotImages' with instances of UIImage objects.
Stone Preston
42,016 PointsStone Preston
42,016 Pointsdid you put that code before or after your array init. it needs to go after. If you passed that last challenge your code should have worked, at least it looked like it should. Unless you cant reference the animationImage property using dot notation but I doubt thats it
Paul Denlinger
3,292 PointsPaul Denlinger
3,292 PointsI place the new line of code after the previous line, after that first line tested and passed.
Any other suggestions?
Stone Preston
42,016 PointsStone Preston
42,016 Pointstry just imageView.animationImages instead of self.ImageView
Paul Denlinger
3,292 PointsPaul Denlinger
3,292 PointsOK, that worked.
Also finished the two remaining tasks.
Thank you.
Stone Preston
42,016 PointsStone Preston
42,016 Pointsno problem