如何在代码中创建图像选择器?
我使用iOS 6.0,使用ARC,用于ipad。
我希望能够选择图片并以某种方式获得所选图像的UIImage。
我确实添加了代表: 在此处输入代码
在viewDidLoad方法中做了
enter code here
imagePicker = [[UIImagePickerController alloc] init];
并在按钮方法中点击我已经放
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:imagePicker animated:YES];
崩溃发生在
[self presentModalViewController:imagePicker animated:YES];
答案 0 :(得分:2)
这里有一些教程http://www.raywenderlich.com/130/how-to-write-a-custom-image-picker-like-uiimagepicker和http://mobileorchard.com/ios-advanced-programming-the-image-picker/可能对您有帮助
答案 1 :(得分:0)
我的一个项目中有类似的代码,但我有
[self presentViewController:imagePicker animated:YES completion:nil];
而不是
[self presentModalViewController:imagePicker animated:YES];
试一下,看看它是否有效。注意presentViewController而不是presentModalViewController。
答案 2 :(得分:0)
在.h
@property (strong) UIPopoverController *pop;
在你的按钮implimentation下的r .m
文件中添加如下内容:
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