将图像从一个视图传递到其他iOS
我的应用程序中有2个将图像从一个视图传递到其他iOS,ios,objective-c,cocoa-touch,uiviewcontroller,uiimagepickercontroller,Ios,Objective C,Cocoa Touch,Uiviewcontroller,Uiimagepickercontroller,我的应用程序中有2个UIViewControllers 在1stviewController中,我在工具栏中有一个ui按钮 当我单击按钮时,它会显示一个ui操作表,用于选择是从照相机还是从多媒体资料中拍照 例如,当我选择从“多媒体资料”中拍照并选择一张图片时,它会在第一个视图控制器中显示该图片 我想要的是从gallery photos或照相机中拍摄一张照片,然后转到2ndviewController并在2ndviewController中显示图像 我搜索了很多,尝试了很多代码,但都不起作用 这是
UIViewController
s
viewController
中,我在工具栏中有一个ui按钮李>
当我单击按钮时,它会显示一个ui操作表
,用于选择是从照相机还是从多媒体资料中拍照
例如,当我选择从“多媒体资料”中拍照并选择一张图片时,它会在第一个视图控制器中显示该图片
我想要的是从gallery photos或照相机中拍摄一张照片,然后转到2ndviewController
并在2ndviewController
中显示图像
我搜索了很多,尝试了很多代码,但都不起作用
这是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
你能帮帮我吗。
很抱歉我的英语不好,谢谢您似乎想在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];
}
感谢您的回复,我现在更改了代码,它始终返回到第一视图,不显示任何图像。您的意思是imagePicker始终返回到第一视图??当我从galery照片中拾取图片时,它会像以前一样返回到第一视图,并且不会显示我选择的图像。问题是,它不会返回到第二个视图,而是始终返回到第一个视图。谢谢你的图像采集器在哪?第一视图还是第二视图?UIImagePickerController返回到您显示它的位置。它不会显示在第一个视图中,我无法访问第二个视图,因为我总是返回第一个视图,这里是指向我的项目的链接,我上载了它,非常感谢您的帮助。