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

Ribbit: Sending Image/Video to Parse

Okay... I sent the file to Parse to send to a user. However, when I run the app, I get a warning that stops the app from finishing.

2014-05-25 17:21:32.440 Ribbit[45968:60b] Warning: Attempt to present <UIImagePickerController: 0x9aa1850> on <UITabBarController: 0x9a4e850> while a presentation is in progress!

It's on this line:

[self.image drawInRect:newRectangle];

Here's my whole resizeImage method:

- (UIImage *)resizeImage:(UIImage *)image toWidth:(float)width andHeight:(float)height {
    CGSize newSize = CGSizeMake(width, height);
    CGRect newRectangle = CGRectMake(0, 0, width, height);
    UIGraphicsBeginImageContext(newSize);
    [self.image drawInRect:newRectangle];
    UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return resizedImage;
}

1 Answer

The error you listed means you are tying to present a UIImagePickerController on a UITabBarController before another view has finished being presented. This generally occurs when methods are called from -(void)viewWillAppear as opposed to -(void)viewDidAppear. The latter must be used to present new views so that the first view can be presented.

Another way this can occur is through the following:

// Error
[viewController1 dismissViewControllerAnimated:YES completion:NULL];
[self presentViewController:viewController2 animated:YES completion:NULL];

// No Error
[viewController1 dismissViewControllerAnimated:YES completion:^{
    [self presentViewController:viewController2 animated:YES completion:NULL];
}];

In order to present a new view, you must make sure no other views are tying to be presented/dismissed.