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
M Miguel
563 PointsI can't pass the code challenge for adding subViews. Please help.
Can anyone tell me what is wrong with my code?
UIView *catView = [[UIView alloc] init];
UIImage *image = [UIImage imageNamed:@"lolcat.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage: image];
[self.view addSubview:imageView];
I can't seem to pass the 3rd task which just simply asks me to add the UIImageView as a subview to the instance of UIView named 'catView'.
4 Answers
Michael Jones
Python Development Techdegree Graduate 38,554 PointsHey...The answer is -
[catView addSubview:imageView];
The 'View' you're trying to access is 'catView'. You don't need to access 'self'.
Maximilian Barnes
764 PointsI cant also complete this challenge due to close enough reasons but i believe in your code where [self.view addSubview:imageView]; is the "addSubview" is supposed to be "insertSubview". Basically the final product SHOULD look something like this- [self.view insertSubview:imageView atIndex:0]; :D There may be a bug or slight program error with that code challenge. :/
M Miguel
563 PointsHi Michael. Thank you. I appreciate it a lot. Hi Maximillian, I'm glad we're over this challenge now.:)
Michael Jones
Python Development Techdegree Graduate 38,554 PointsVery welcome.
Maximilian Barnes
764 PointsYea :D
M Miguel
563 Points:D
Michael Jones
Python Development Techdegree Graduate 38,554 PointsJust out of interest, where are you both from?
Maximilian Barnes
764 PointsAmerica
M Miguel
563 PointsI'm based in the Philippines. How about you, Michael?
Michael Jones
Python Development Techdegree Graduate 38,554 PointsCool. I'm based in the UK. I love how Treehouse is available to everyone around the world.
How long have you both been members? Are you both new to the programming scene?
Maximilian Barnes
764 Pointsnot really used to do a bit of Java but otherwise yeah :D Oh and whats wrong with this code for the animating robot pictures- UIImage *robotImages= [UIImage imageNamed:@"robot.png"]; self.imageView = [[UIImageView alloc] initWithImage:robotImages];
/* Write your code below this line */
self.imageView.animationImages = [[NSArray alloc] initWithObjects: [UIImage imageNamed:@"Robot1"], [UIImage imageNamed:@"Robot2"], [UIImage imageNamed:@"Robot3"], [UIImage imageNamed:@"Robot4"], nil];
M Miguel
563 PointsI've been into HTML and CSS for a while and decided to explore iOS app development. Treehouse has been great for a newbie like myself.
Michael Jones
Python Development Techdegree Graduate 38,554 PointsMaximillian you would need to create an Array called 'robotImages', then you'll allocated the images to that array.
Like this -
NSArray *robotImages = [[NSArray alloc] initWithObjects:[UIImage imageNamed:@"Robot1"], [IImage imageNamed:@"Robot2"], [UIImage imageNamed:@"Robot3"], [UIImage imageNamed:@"Robot4"], nil];
Awesome...Have you got any sites live at the moment Elmi?
Maximilian Barnes
764 Pointsthanks again!
Maximilian Barnes
764 PointsMichael how long have you been programming ?
Michael Jones
Python Development Techdegree Graduate 38,554 PointsI've been doing it on and off for about 6-7 months now. Starting to get the hang of it now, some bits are still over my head at times.
Looking to starting a new career as a iOS developer or back end developer.
M Miguel
563 PointsHi, Michael, not yet. I'm currently working for my friend's portfolio site but I'm really interested in iOS development and perhaps I'll be focusing on it.
Maximilian Barnes
764 PointsElmi how far are you on IOS development?
M Miguel
563 PointsMaximillian, I just finished the 3rd adventure and I'll be continuing tomorrow since it's dinner time in our place and I'm preparing to go out tonight. I guess you're way ahead now. :)
Maximilian Barnes
764 Pointslol yea :D
Maximilian Barnes
764 Pointsactually i just finished stage 3 so you still have a chance to catch up :P
M Miguel
563 Pointshahaha. :)
I'll see you tomorrow then. :)
Maximilian Barnes
764 PointsYup well see you then :)
M Miguel
563 PointsHi Max and Michael, The challenges are getting more and more difficult. Would you happen to know how to set the animation images property of "imageView" to "robotImages"?
Michael Jones
Python Development Techdegree Graduate 38,554 PointsHere you go....
imageView.animationImages = robotImages;
M Miguel
563 PointsI passed the code challenge. Thank you Michael. I'm learning a lot this time. :)
Michael Jones
Python Development Techdegree Graduate 38,554 PointsNo worries, keep up the good work!!
M Miguel
563 PointsThank you. We'll talk soon. :)
Maximilian Barnes
764 PointsHello again
M Miguel
563 PointsHi Max. Have a nice day ahead. :)
Maximilian Barnes
764 PointsWhat part of ios dev are you in?
M Miguel
563 PointsHi Max, I just finished the course by Amit. :) How about you?
Maximilian Barnes
764 Pointssame :D
M Miguel
563 Pointsthat's great. This is very addictive. :)
Maximilian Barnes
764 Pointsyup
M Miguel
563 Points:)
Maximilian Barnes
764 PointsMaximilian Barnes
764 PointsThanks!!
Michael Jones
Python Development Techdegree Graduate 38,554 PointsMichael Jones
Python Development Techdegree Graduate 38,554 PointsNo worries.
Keep up the good work!!