UIImagePickerController无法正常工作

时间:2013-01-05 13:19:04

标签: xcode uinavigationcontroller uiimageview uiimage uiimagepickercontroller

我正在使用xcode 4.5.2,我想在基于navigationBar的app上使用UIImagePickerController,除非用户选择图像后图像保持空白,否则一切都很完美。

用户应该在按钮上选项卡 - >选择相机或现有的ActionSheet->选择图像,然后......没有显示!!

我已经添加了代理<UINavigationControllerDelegate,UIActionSheetDelegate, UIImagePickerControllerDelegate>并正确地将IB中的所有内容联系起来..我非常确定,除非我不确定这种方法:

- (void) imagePickerController:(UIImagePickerController *)thePicker didFinishPickingMediaWithInfo:(NSDictionary *)imageInfo{

[[imgPicker parentViewController] dismissViewControllerAnimated:YES completion:nil];

    UIImage *img = [imageInfo objectForKey:@"UIImagePickerControllerEditedImage"];
    currentImg.image = nil;
    self.currentImg.image = img;

}

我也用过这个:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo {
image.image = img;
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
}

什么都没发生..

2 个答案:

答案 0 :(得分:1)

<强>解决

错过了添加此行:

    self.imgPicker.delegate = self;

在viewDidLoad中:)

答案 1 :(得分:0)

尝试使用[info objectForKey:UIImagePickerControllerOriginalImage];而不是使用已编辑的图像。通常你会检查编辑过的图像是否存在,如果存在则使用它,如果不存在则使用原始图像。

这样的事情:

- (void) imagePickerController:(UIImagePickerController *) picker didFinishPickingMediaWithInfo:(NSDictionary *) info {
    NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
    UIImage *originalImage, *editedImage, *imageToSave;

    // Handle a still image capture
    if (CFStringCompare ((CFStringRef) mediaType, kUTTypeImage, 0) == kCFCompareEqualTo) {
        editedImage = (UIImage *) [info objectForKey:
                                   UIImagePickerControllerEditedImage];
        originalImage = (UIImage *) [info objectForKey:
                                     UIImagePickerControllerOriginalImage];

        if (editedImage) {
            imageToSave = editedImage;
        } else {
            imageToSave = originalImage;
        }
    }

    self.currentImg.image = imageToSave;
}