我的应用中有2 UIViewController
个。
viewController
中,我在工具栏中有一个UIButton
。 UIActionSheet
以选择是从相机还是从图库中拍摄照片。viewController
中显示图片。我想要的是从图库照片或相机拍摄照片,然后转到第二 viewController
并在第二 {中显示图片{1}}。
我搜索了很多并尝试了很多代码,但它不起作用。
以下是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
你可以帮帮我吗
抱歉我的英语不好,谢谢
答案 0 :(得分:0)
您似乎想要在FirstViewController
选择图片并将其显示在SecondViewContoller
中。但是,您没有做任何事情要切换到SecondViewController
并将所选图片传递给ViewController.m
。
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
SecondViewController *secondViewController = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
secondViewController.imageButton.image = image;
[self.navigationController pushViewController:secondViewController animated:YES];
}