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

iOS

I 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

Hey...The answer is -

[catView addSubview:imageView];

The 'View' you're trying to access is 'catView'. You don't need to access 'self'.

Thanks!!

No worries.

Keep up the good work!!

I 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. :/

Hi Michael. Thank you. I appreciate it a lot. Hi Maximillian, I'm glad we're over this challenge now.:)

Very welcome.

Yea :D

:D

Just out of interest, where are you both from?

America

I'm based in the Philippines. How about you, Michael?

Cool. 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?

not 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];

I'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.

Maximillian 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?

thanks again!

Michael how long have you been programming ?

I'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.

Hi, 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.

Elmi how far are you on IOS development?

Maximillian, 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. :)

lol yea :D

actually i just finished stage 3 so you still have a chance to catch up :P

hahaha. :)

I'll see you tomorrow then. :)

Yup well see you then :)

Hi 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"?

Here you go....

imageView.animationImages = robotImages;

I passed the code challenge. Thank you Michael. I'm learning a lot this time. :)

No worries, keep up the good work!!

Thank you. We'll talk soon. :)

Hello again

Hi Max. Have a nice day ahead. :)

What part of ios dev are you in?

Hi Max, I just finished the course by Amit. :) How about you?

same :D

that's great. This is very addictive. :)

yup

:)