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

Resizing an Image task 2

Notice that an important line is missing from the block of code that creates a resized version of the image stored in the 'image' property. Fix it! Hint: You'll need to redraw the image in the new rectangle.

#import "LatergramViewController.h"

@implementation LatergramViewController

- (IBAction)upload {

 if (self.image != nil && [self.caption length] != 0) {
    CGSize newSize = CGSizeMake(320.0f, 480.0f);
    CGRect newRectangle = CGRectMake(0, 0, 320.0f, 480.0f);
    UIGraphicsBeginImageContext(newSize);
    }

   // Task 2: Line missing here! How do we draw the image in the resized context?

 [self.image drawInRect:newRectangle];

    UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    // Rest of code omitted for brevity!
}

@end

I added [self.image drawInRect:newRectangle]; However its not working. Can someone point me in the right direction.

12 Answers

#import "JonyIveViewController.h"

@implementation JonyIveViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Rest of viewDidLoad code omitted
}


- (IBAction)redesignIOS:(id)sender {

    // Magic redesign code omitted

    NSLog(@"True simplicity is...where you go, Yeah, well, of course.");
}

@end

This should work

Yo almost there. Its the right code, but you have a syntax error . Just put a single pair of {} around the entire block and that should fix your problem.

Bummer! Compilation Error! Check your syntax: make sure you refer to properties using the 'self' keyword! That is what I am currently getting.

Yeah yeah it has nothing to do with your actual lines of code, just review where you put your curly braces ({ }) and you will get the answer, I promise you.

(i know you want me to just tell you exactly whats wrong but when you see it you'll face palm. Just look through your code again)

*Face Palm Thanks for the help.

How I felt 30 mins ago..... SMASH!

How I feel now.... SMASH!

no problem man

Nice work Meek.

This is totally bogus!

Notice that the curly brace is ABOVE the line that says:

// Task 2: Line missing here! How do we draw the image in the resized context?

...in the (starting) skeleton code as given:

    UIGraphicsBeginImageContext(newSize);
    }  //<======= the 'out of place' curly brace

   // Task 2: Line missing here! How do we draw the image in the resized context?

When the new line of code is added,

it needs be situated such that

the curly brace is BELOW the added line:

    UIGraphicsBeginImageContext(newSize);
    //new line of code added...
    [self.image drawInRect:newRectangle];
    }

   // Task 2: Line missing here! How do we draw the image in the resized context?

Or...in in other words...if the Treehouse people were actually "playing fair" the skeleton code comment line:

// Task 2: Line missing here! How do we draw the image in the resized context?

...should have been above the curly brace at the start of that part of the challenge to avoid any confusion [IMHO]


Thanks, though, to Meek D for the clue

(even though it would have been clearer

if he learned to use the forum's markup tick marks).

On the topic of face palming............ Have you completed the "Getting Up To Speed" code challenge by chance? I am right now the driver of the struggle bus and just cant read this code

I don't think I have do you have a link to the quiz?

Yeah, I finished everything else with the project except this. Don't judge, I know it's super simple haha

http://teamtreehouse.com/library/getting-up-to-speed

Owe you big time!

Cheers, no worries!

i still dont get it...

Hey, which part are you confused about?

I also got this part : [self.image drawInRect:newRectangle]; But I don't know where to put the curly braces. sigh Javascript is so much easier than this

i fixed it just

  • (IBAction)upload { if (self.image != nil && [self.caption length] != 0) { CGSize newSize = CGSizeMake(320.0f, 480.0f); CGRect newRectangle = CGRectMake(0, 0, 320.0f, 480.0f); UIGraphicsBeginImageContext(newSize); [self.image drawInRect:newRectangle]; UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); // return resizedImage; }

}

thanks!

thank you Meek D! that really helped a lot