1

我正在嘗試編寫一個應用程序,允許用戶從iPad上的照片庫中選擇圖像。我在網上做了完全的消息來源說,它應該完成,但是當我點擊按鈕只有箭頭顯示在屏幕上,沒有別的。應顯示圖像的彈出窗口不顯示。任何人都可以告訴我爲什麼會發生這種情況?這裏是我的代碼:Popover不顯示iPad照片庫

 UIImagePickerController *picker = [[UIImagePickerController alloc] init]; 
     [picker setDelegate:self]; 

     [picker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary]; 
     [picker setAllowsEditing:YES]; 

     popoverController = [[UIPopoverController alloc] initWithContentViewController:picker]; 
     [popoverController presentPopoverFromRect:self.view.frame inView:[self view] permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 

回答

0

我知道這是對已故回答,但如果你在它已經有興趣,這可能會爲你工作:

在.h文件中,給出了這樣的代表:

@interface ViewController : UIViewController <UIPopoverControllerDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate> 

創建酥料餅作爲一個屬性:

@property (nonatomic, strong) UIPopoverController *popoverController; 

最後在.m文件:

-(IBAction)showPhotoLibray:(id)sender 
{ 
    BOOL hasGellery = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]; 
    UIImagePickerController* picker = [[UIImagePickerController alloc] init]; 
    picker.delegate = self; 
    picker.sourceType = hasGellery ? UIImagePickerControllerSourceTypePhotoLibrary : UIImagePickerControllerSourceTypePhotoLibrary; 
    if (self.popoverController != nil) 
    { 
     [self.popoverController dismissPopoverAnimated:YES]; 
     self.popoverController=nil; 
    } 

    self.popoverController = [[UIPopoverController alloc] initWithContentViewController:picker]; 
    CGRect popoverRect = [self.view convertRect:[self.theViewObject frame] 
             fromView:[self.theViewObject superview]]; 
    popoverRect.size.width = MIN(popoverRect.size.width, 300) ; 
    popoverRect.origin.x = popoverRect.origin.x; 
    [self.popoverController 
    presentPopoverFromRect:popoverRect 
    inView:self.view 
    permittedArrowDirections:UIPopoverArrowDirectionAny 
    animated:YES]; 
} 

的self.theViewObject是調用方法的對象的視圖控制器的出口,例如的UIButton