[英]Fails to load image from UIImagePickerController on next ViewController after segue
I am trying to load a picture selected on UIImagePickerController
on the next view controller. 我正在尝试在下一个视图控制器上加载在
UIImagePickerController
上选择的图片。 i did some search on similar threads and found a few that helped me set it up, but the image does not really get 'transfered' to the next view controller. 我在类似的线程上进行了一些搜索,发现有一些可以帮助我进行设置,但是图像并没有真正“转移”到下一个视图控制器。
this is my code for the didFinishPickingImage and prepareForSegue: 这是我的didFinishPickingImage和prepareForSegue的代码:
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo
{
self.imageChosen = image;
[picker dismissModalViewControllerAnimated:NO];
[self performSegueWithIdentifier:@"Edit" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"Edit"]){
EditViewController *editViewController =
(EditViewController *)segue.destinationViewController;
editViewController.imageView.image = self.imageChosen;
}
I am getting the segue running to the EditViewController
, but the imageView there doesnt load the picture. 我让segue运行到
EditViewController
,但是那里的EditViewController
不会加载图片。 I guess the assignment is wrong somehow but I fail to see how. 我猜该作业某种程度上是错误的,但是我看不到如何。
When you try to set image to EditViewController
UIImageView
it doesn't not exist because EditViewController
not loaded yet. 当您尝试将图像设置为
EditViewController
UIImageView
该图像不存在,因为尚未加载EditViewController
。 Instead of setting image to UIImageView
directly create an instance variable in EditViewController
that will hold image. 不用将图像设置为
UIImageView
而是直接在EditViewController
中创建一个实例变量来保存图像。 And than assign this image to UIImageView
in viewDidLoad:
然后将此图像分配给
viewDidLoad:
UIImageView
viewDidLoad:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"Edit"]){
EditViewController *editViewController =
(EditViewController *)segue.destinationViewController;
editViewController.image = self.imageChosen;
}
//EditViewController.h
...
@property (nonatomic, strong) UIImage *image;
...
//EditViewController.m
- (void)viewDidLoad {
...
self.imageView.image = self.image;
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.