1

如何在代码中创建图像选择器?

我将 iOS 6.0 与 ARC 一起用于 ipad。

我希望能够选择图片并以某种方式获取所选图像的 UIImage 。

我确实添加了代表:在此处输入代码

在 viewDidLoad 方法中做了 enter code hereimagePicker = [[UIImagePickerController alloc] init];

并在单击的按钮方法中我放了

imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:imagePicker animated:YES];

崩溃发生在

[self presentModalViewController:imagePicker animated:YES];
4

3 回答 3

2

这里有一些教程http://www.raywenderlich.com/130/how-to-write-a-custom-image-picker-like-uiimagepickerhttp://mobileorchard.com/ios-advanced-programming-the -image-picker/可能对你有帮助

于 2013-01-22T21:28:47.793 回答
0

在中添加属性.h

@property (strong) UIPopoverController *pop;

.m在您的按钮实施下的r文件中添加如下内容:

if (self.pop) {
        [self.pop dismissPopoverAnimated:YES];

    }


UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
       imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
       imagePickerController.delegate = self;
       imagePickerController.allowsEditing = YES; //if you want to edit the image

       self.pop=[[UIPopoverController alloc] initWithContentViewController:imagePickerController];
       //choose the direction of the arrow for the popover
       [self.pop presentPopoverFromRect:((UIButton *)sender).bounds inView:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
  }
}

确保您<UIPopoverControllerDelegate>在 .h 中设置了您的委托

于 2013-01-22T21:44:59.540 回答
0

我的一个项目中有类似的代码,但我有

[self presentViewController:imagePicker animated:YES completion:nil];

代替

[self presentModalViewController:imagePicker animated:YES];

试试看它是否有效。注意 presentViewController 而不是 presentModalViewController。

于 2013-01-22T21:40:37.130 回答