Problem UIImagePickerControllerDelegate, didFinishPickingMediaWithInfo not called
Hey guys, I know it has been asked more often, but the answers to their questions don't seem to apply here.
My didFinishPickingMediaWithInfo method doesn't get called :(
Here is my code:
The .h-file:
#import <UIKit/UIKit.h>
@interface DevicePictureController : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate> {
UIImageView *photo;
UIButton *selectPhoto;
UIButton *takePhoto;
NSMutableDictionary *listLocations;
NSMutableDictionary *listDevices;
UIImagePickerController *picker;
}
@property (nonatomic, retain) IBOutlet UIImageView *photo;
@property (nonatomic, retain) IBOutlet UIButton *selectPhoto;
@property (nonatomic, retain) IBOutlet UIButton *takePhoto;
@property (nonatomic, retain) UIImagePickerController *picker;
-(IBAction)selectPicture:(id)sender;
@end
The .m-file: #import "DevicePictureController.h"
@implementation Devi开发者_高级运维cePictureController
@synthesize photo, selectPhoto, takePhoto, picker;
- (void)viewDidLoad
{
[super viewDidLoad];
listLocations = [[NSMutableDictionary alloc] init];
listDevices = [[NSMutableDictionary alloc] init];
picker = [[UIImagePickerController alloc] init];
}
-(IBAction)selectPicture:(id)sender {
picker.delegate = self;
picker.allowsEditing = YES;
if ((UIButton *)sender == selectPhoto) {
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
else {
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
[self presentModalViewController:picker animated:YES];
}
-(void)imagePickController:(UIImagePickerController *)picked didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picked dismissModalViewControllerAnimated:YES];
NSLog(@"Geselecteerd: %@", [info objectForKey:UIImagePickerControllerEditedImage]);
//photo = [[UIImageView alloc] init];
[photo setImage:[info objectForKey:UIImagePickerControllerEditedImage]];
}
@end
So, my album or my camera gets loaded/activated properly, but when I click 'Use' or the photo, I only see the 2 buttons and an emtpy UIImageView after the view is dismissed. 'photo' is connected to UIImageView, 'selectPhoto' and 'takePhoto' are connected to their buttons, 'selectPicture' is connected to both the buttons' Touch Up Inside-action. Can anybody help me out?
You have a typo in your delegete method.
It should be
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
but you have
- (void)imagePickController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
- (void)viewDidLoad
{
[super viewDidLoad];
listLocations = [[NSMutableDictionary alloc] init];
listDevices = [[NSMutableDictionary alloc] init];
picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
}
精彩评论