【发布时间】:2014-01-22 19:23:48
【问题描述】:
我的应用中有 2 个UIViewControllers。
- 在 1st
viewController中,我在工具栏中有一个UIButton。 - 当我点击按钮时,它会显示一个
UIActionSheet来选择是从相机还是从图库中拍照。 - 当我选择,例如从图库中拍照并选择一张图片时,它会在第一个
viewController中显示图片。
我想要的是从画廊照片或相机中拍照并转到2nd viewController 并在2nd viewController 中显示图像.
我搜索了很多代码并尝试了很多代码,但它不起作用。
这里是ViewController.m的代码
- (IBAction)PictureButton:(UIButton *)sender {
NSLog(@"Click button take picture in toolbar view 1");
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Photo"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:@"Picture From Camera", @"Picture From Gallery", nil];
[actionSheet setTag:1001];
[actionSheet showInView:self.view];
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
switch (buttonIndex)
{
case 0: {
// Take a picture from camera
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:picker animated:YES];
}
break;
case 1: {
// take a picture from gallery photos
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self.view addSubview:toolbar];
[self presentModalViewController:picker animated:YES];
}
break;
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
}
在我的第二个视图中,我创建了一个UIImageView 这是我在SecondViewController.h 中的代码
@interface SecondViewController : UIViewController
@property (weak, nonatomic) IBOutlet UIImageView *imageButton;
@end
你能帮帮我吗。
对不起我的英语不好,谢谢
【问题讨论】:
标签: ios objective-c cocoa-touch uiviewcontroller uiimagepickercontroller