1

我正在使用 xcode 4.5.2 并且我想在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];
}

什么也没发生..

4

2 回答 2

1

解决了

错过了添加这一行:

    self.imgPicker.delegate = self;

在 viewDidLoad :)

于 2013-01-06T03:40:42.090 回答
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;
}
于 2013-01-06T02:56:38.617 回答