1

我使用的是xcode 4.5.2,我想在我的基於導航欄的應用程序上使用UIImagePickerController,除非在用戶選擇圖像後圖像保持空白,否則一切都可以正常工作。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]; 
} 

並沒有發生任何事..

回答

1

解決

錯過了加入這一行:

self.imgPicker.delegate = self; 
在viewDidLoad中

:)

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; 
} 
相關問題