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
John Pettingill
841 PointsCode Challenge Trouble: Programming a Background Image in IOS
The 3rd question of the code challenge in "Programming a Background Image" does not quite make sense to me. Here is the code I have for the first two questions which are fine:
UIImage * image02 = [UIImage imageNamed:@"background"]; UIImageView * imageView = [[UIImageView alloc] initWithImage:image02];
And here is the answer I am giving the 3rd question that will not pass:
UIView* catView = [UIView alloc]; [catView insertSubview:background atIndex:0];
I plugged this into xcode and it compiles fine--any suggestions?
Thank you in advance...
Alejandro Calzada
3,880 PointsJohn did you pass the 3rd section of the code? What am I missing or leaving out? [catView addSubview:imageView atIndex:0];
John Pettingill
841 PointsAlejandro,
I apologize, I have been away for a while.
First off, "catView" is all ready created, so you do not need to instantiate it like:
UIView * catView
You can just start using catView and it's methods, such as addSubview.
[catView ...
You also do not need to add "indexAt" to the method. Let me know if this helps.
John
2 Answers
Ernest Grzybowski
Treehouse Project ReviewerI also agree that it the question is worded a little funny.
Add the UIImageView as a subview to the instance of UIView named 'catView'.
Essentially, the first half of the question is pretty easy.
Add the UIImageView as a subview
We know it is going to look something like this:
addSubview:imageView
The second half also seems to throw most people off.
to the instance of UIView named 'catView'.
Since catView is already an instance of UIView this means that you can simply use catView.
You have to read the question very carefully, as right off the bat you should notice you are asked to add and not insert.
You are left with addSubview:imageView and catView. Mix that in with a '[and a]` and you will be able to complete the challenge.
If you need more help, please let me know.
John Pettingill
841 PointsGot it...thanks so much!
Alejandro Calzada
3,880 PointsThank you too.
Alejandro Calzada
3,880 PointsHey John I am right with you on this problem. This is the first time that I have been really stuck. I think I've tried everything. Did you pass it and how. Would appreciate a little help. Alex
Ernest Grzybowski
Treehouse Project ReviewerAlejandro what have you tried that you are failing?
Alejandro Calzada
3,880 PointsErnest, thanks for responding. The third section of the Code challenge is what I am having problems. In code challenges "self" is not used and this throws me for a loop. I am not at my laptop but I enter code that looks something like this. [UIView* catViewaddSubview: imageView atIndex:0];
Crystal Jackson
Courses Plus Student 2,017 PointsFigured it out! [catView addSubview:imageView];
I was failing at this level...
I wrote "[self.view addSubview:catView];"
Here was the whole thing the wrong way (was stuck at third level):
UIView *catView = [[UIView alloc] init];
/* Write your code below this line */
UIImage *image = [UIImage imageNamed:@"lolcat.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
[self.view addSubview:catView]; <<------------this part was wrong "
Best, cj
Alejandro Calzada
3,880 PointsAlejandro Calzada
3,880 PointsHey John, I think I am going in circles. Did you figure this out? If you could help that would be great.