gpt4 book ai didi

iOS 如何启动图像选择器

转载 作者:行者123 更新时间:2023-11-28 22:05:37 26 4
gpt4 key购买 nike

我有一个 UIButton,当用户点击它时,我想启动图像选择器 Controller

我已经配置了我认为足够的配置,但我不知道我必须传递给该图像选择器以开始工作的消息是什么

这是我的代码

#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

我已经设置了正确的协议(protocol):

@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 如何启动图像选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24098887/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com