我正在尝试使用UIPopoverContoller加载图像

时间:2012-01-13 03:56:18

标签: ios uipopovercontroller

我在xcode 4.2中制作了一个简单的通用图像加载器,它允许您从电话库中选择一张照片并将其显示在屏幕上。它是一个通用的应用程序,并使用UIImagePickerController提取菜单并选择一张照片,但是当点击ipad上应该显示popoverController按钮的按钮时,它会返回一个错误。

#import "ImageLoaderViewController.h"

@implementation ImageLoaderViewController
@synthesize imageView = _imageView;
@synthesize popoverController;

-(void)selectPhoto
{
    NSLog(@"YYOYOYOYOY");

    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    NSLog(@"now i am here");
    imagePicker.delegate = self;

    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
    {
        NSLog(@"camera");
        imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    }
    else{
        NSLog(@"NO camera");
        imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;}
    if(IS_IPHONE)
    {
        NSLog(@"is an iphone");
        [self presentModalViewController:imagePicker animated:YES];
    }

    else
    {
        if ([popoverController isPopoverVisible])
            [popoverController dismissPopoverAnimated:NO];
        popoverController = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
        popoverController.delegate = self;
        [popoverController presentPopoverFromBarButtonItem:self.navigationItem.rightBarButtonItem permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

    }

}

-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    _imageView.image = [info objectForKey:UIImagePickerControllerOriginalImage];
    if(IS_IPHONE)
        [self dismissModalViewControllerAnimated:NO];
}

-(void) popoverControllerDidDismissPopover:(UIPopoverController *)popoverController
{
    [popoverController dismissPopoverAnimated:NO];
}



@end

0 个答案:

没有答案