问题UIImagePickerControllerDelegate,didFinishPickingMediaWithInfo未调用

时间:2011-04-07 12:17:34

标签: iphone objective-c xcode camera xcode4

嘿伙计们, 我知道它已被更频繁地询问,但他们的问题的答案似乎并不适用于此。

我的didFinishPickingMediaWithInfo方法没有被调用:(

这是我的代码:

.h文件:

#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

.m文件:     #import“DevicePictureController.h”

@implementation DevicePictureController
@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

因此,我的相册或相机被正确加载/激活,但是当我点击“使用”或照片时,我只会在视图被取消后看到2个按钮和一个emtpy UIImageView。 'photo'连接到UIImageView,'selectPhoto'和'takePhoto'连接到它们的按钮,'selectPicture'连接到两个按钮的Touch Up Inside-action。 有人可以帮帮我吗?

2 个答案:

答案 0 :(得分:5)

您的委托方法中存在拼写错误。

应该是

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

但你有

- (void)imagePickController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

答案 1 :(得分:1)

- (void)viewDidLoad
{
[super viewDidLoad];
listLocations = [[NSMutableDictionary alloc] init];
listDevices = [[NSMutableDictionary alloc] init];
picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
}