2012-07-31 117 views
0

我試圖從圖庫中獲取圖像並將其顯示在UIImageView中。我的問題是顯示這個圖像。我的代碼:使用UIPopover從圖庫獲取圖像並將其顯示

- (void)getMediaFromSource:(UIImagePickerControllerSourceType)sourceType { 

    UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init]; 
    imagePickerController.delegate = self; 
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 

    self.popController = [[UIPopoverController alloc] initWithContentViewController:imagePickerController]; 
    self.popController.delegate = self; 
    [self.popController presentPopoverFromRect:[fromGalaryButton frame] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 
} 

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { 
    [self.popController dismissPopoverAnimated:YES]; 
    self.image = [info objectForKey:UIImagePickerControllerEditedImage]; 
    [self updateDisplay]; 
} 

-(void)updateDisplay { 
    self.imageView.image = self.image; 
    self.imageView.hidden = NO; 
    [self.imageView reloadInputViews]; 
} 

我的self.imageView顯示正常。但是沒有任何形象。我的問題是?

回答

2

如果你只是在影像擷取從畫廊則代碼didFinishPickingMediaWithInfo方法行應該是:

self.image = [info objectForKey:UIImagePickerControllerOriginalImage]; 

你也剛剛從方法中更新的ImageView這樣:

self.imageView.image = [info objectForKey:UIImagePickerControllerOriginalImage]; 

這是我如何做:

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    picker = [[UIImagePickerController alloc] init]; 
    picker.delegate = self; 
    imagePickerPopover = [[UIPopoverController alloc] initWithContentViewController:picker]; 

} 

- (IBAction)getPhoto:(id)sender { 

if(sender == choosePhotoButton) { 
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
    [imagePickerPopover presentPopoverFromBarButtonItem:choosePhotoButton permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES]; 
} 
} 

    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { 
     [imagePickerPopover dismissPopoverAnimated:YES]; 
     imageViewer.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"]; 

    } 
+0

問題不在這裏.. – RomanHouse 2012-07-31 19:10:36

+0

你能夠從UIImagePicker中選擇一張圖片,但圖片不會顯示在圖片視圖中?或者,你是否無法首先選擇圖像? – 2012-07-31 19:16:18

+0

Yeap,我檢查了它['UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]'。 – RomanHouse 2012-07-31 19:27:03

相關問題