Bronze Challenge: My solution


First topic on this forum.

From the UIImagePickerController class reference:

Since this is a property on the UIImagePickerController, all we need to do is set the corresponding property on the controller to YES. We declared the controller in the function that is executed after the camera icon is pressed, takePicture. So this is where we set allowsEditing to YES. Using dot operators to access the property:

[code]- (IBAction)takePicture:(id)sender
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

imagePicker.allowsEditing = YES;

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
    [imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
} else {
    [imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[imagePicker setDelegate:self];
[self presentViewController:imagePicker animated:YES completion:nil];



In order to use the edited picture, you need to update:

didFinishPickingMediaWithInfo:(NSDictionary *)info



  • (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
    NSString *oldKey = [item imageKey];
    if (oldKey) {
    [[BNRImageStore sharedStore] deleteImageForKey:oldKey];

    UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];

    CFUUIDRef newUniqueID = CFUUIDCreate(kCFAllocatorDefault);
    CFStringRef newUiniqueIDString = CFUUIDCreateString(kCFAllocatorDefault, newUniqueID);
    NSString *key = (__bridge NSString *)newUiniqueIDString;
    [item setImageKey:key];
    [[BNRImageStore sharedStore] setImage:image forKey:[item imageKey]];
    [imageView setImage:image];
    [self dismissViewControllerAnimated:YES completion:nil];

note: The original image and the edited image are both contained in the info NSDictionary


Why do you have to use dot notation for imagePicker.allowsEditing ?
I tried [imagePicker allowsEditing:YES];
But it gives a "No visible @interface for ‘UIImagePickerController’ declares the selector ‘allowsEditing:’


[quote=“notevilkenevil”]Why do you have to use dot notation for imagePicker.allowsEditing ?
I tried [imagePicker allowsEditing:YES];
But it gives a "No visible @interface for ‘UIImagePickerController’ declares the selector ‘allowsEditing:’[/quote]

You will either use a dot notation to set a property like this:
imagePicker.allowsEditing = YES
or use the “set” + property name like this:
[imagePicker setAllowsEditing: YES];

you cannot mix these two fellows!


Thanks for the solution… I was reading all about allowsEditing but couldn’t work out where to use it.

The change from the UIImagePickerControllerOriginalImage to UIImagePickerControllerEditedImage was more straightforward.

Anyway, just to pick up on the discussion of dot-notation versus traditional object-C method notation…

You can mix these two, so that some parts of your line of code are dotted and others are ‘methoded’ (yes, I know that the dot notation is just a short form for calling the accessor methods):

item.valueInDollars = [valueField.text intValue];

Frankly, I prefer the dotted notation, despite BNR’s misgivings, as mentioned in this book and their Objective-C one: If something is a property of an object, then I want to access that property, and I don’t want to really care if I’m setting or getting the property. Also, I like the use of the equals sign to show that something is now set to something.