【问题标题】:Image Picker and pushing image selected to a new view controller图像选择器并将选择的图像推送到新的视图控制器
【发布时间】:2013-07-11 05:49:37
【问题描述】:

我正在尝试使用相机拍摄照片,然后将所选照片传递到另一个视图控制器。我使用 segue 将图像推送到下一个,但它似乎没有得到图像。

pragma mark - UIImagePickerDelegate 方法

//delegate methode will be called after picking photo either from camera or library
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [self dismissViewControllerAnimated:YES completion:nil];

    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];

    [self.collectedImageView setImage:image];

    [self performSegueWithIdentifier:@"photoArea" sender:self];
}

pragma mark - 为 Segue 做准备

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    MESSelectPhotoAreaViewController *photoAreaVC = [segue destinationViewController];

    photoAreaVC.photoImageView.image = self.collectedImageView.image;
}

【问题讨论】:

    标签: ios uiviewcontroller uiimageview uiimage uiimagepickercontroller


    【解决方案1】:

    我猜“photoAreaVC.photoImageView”仍然为空,因为destinationViewController 尚未完全实例化。

    您可以通过在“prepareForSegue:”方法中添加这一行来确认这一点:

    if (photoAreaVC.photoImageView == NULL)
        NSLog( @"photoImageView doesn't yet exist" );
    

    您需要找到一个位置(例如,目标视图控制器中的“UIImage”属性,也许?)来临时存储该图像,直到“viewDidAppear:”或“viewWillAppear:”被调用,在某处“photoImageView”属性指向一个有效的对象。

    【讨论】:

    • 100% 正确。我实际上在第一个实例中不需要 UIImageView,所以我将其更改为图像,然后将图像传递到新的控制器图像实例并使用 viewDidAppear 更新图像视图。谢谢
    • 目前我的应用程序遇到了这个确切的问题,这个答案是我迄今为止找到的最好的答案。尽管出于兴趣,我将如何“暂时隐藏”我的图像,即。我可以把什么代码放在哪里让这个工作?
    • 一个临时(或永久)存储位置可能是您的对象的“UIImage”属性。
    猜你喜欢
    • 2020-11-04
    • 2012-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-30
    • 1970-01-01
    • 2021-02-03
    • 1970-01-01
    相关资源
    最近更新 更多