我有一个UIButton
,当用户单击它时,我想启动图像选择器控制器
我已经配置了我认为已经足够的内容,但是我不知道我必须传递给该图像选择器的消息是什么才能开始工作
这是我的代码
#import "ImagePickerViewController.h"
@interface ImagePickerViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *image;
@end
@implementation ImagePickerViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (IBAction)SelectImage:(id)sender {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc]init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
@end
我已经设置了正确的协议:
@interface ImagePickerViewController : UIViewController < UINavigationControllerDelegate,UIImagePickerControllerDelegate>
@end
最佳答案
您需要出示UIImagePicker
- (IBAction)SelectImage:(id)sender
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc]init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:imagePicker animated:NO completion:nil];
}
关于ios - iOS如何启动图像选择器,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24098887/