如何在UiView中添加UIImagePickerController

3 iphone uiimagepickercontroller ios

如何在TabBarApplication中的UiView中添加UIImagePickerController

Lou*_*nco 15

如果您在选项卡中没有关系,此代码将进入您的视图的ViewController类

如果需要,可以创建一个选择器

UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
// configure it how you want
Run Code Online (Sandbox Code Playgroud)

添加选择器

[self presentViewController:picker animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

您的视图控制器需要声明为

@interface YourViewController :  
   UIViewController<UIImagePickerControllerDelegate, UINavigationControllerDelegate>
Run Code Online (Sandbox Code Playgroud)

你需要实施

- (void)imagePickerController:(UIImagePickerController *)picker 
    didFinishPickingMediaWithInfo:(NSDictionary *)info;
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker;
Run Code Online (Sandbox Code Playgroud)

(第一个应该从info对象获取图像)

在每个消息中,完成后,删除选择器

[self dismissModalViewControllerAnimated:YES];
Run Code Online (Sandbox Code Playgroud)