0

嗨,在我的应用程序中,我可以拍照或从库中选择一张照片并将其显示在图像视图中

但我的问题是如何添加第二个图像视图并在其中显示图像

这是我的代码

- (IBAction)TakePhoto:(id)sender {
picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
[picker setSourceType:UIImagePickerControllerSourceTypeCamera];
[self presentViewController:picker animated:YES completion:NULL];
}

- (IBAction)ChoosePhoto:(id)sender {    
picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
[picker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:picker animated:YES completion:NULL];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    image = [info objectForKey:UIImagePickerControllerOriginalImage];
    [ImageView setImage:image];    // "myImageView" name of any UImageView.
    [self dismissViewControllerAnimated:YES completion:NULL];
}

-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[self dismissViewControllerAnimated:YES completion:NULL];
}
4

1 回答 1

0

我从您的问题中认为您将一张一张地选择两张图片。

来自相机或照片库。

试试这个:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    image = [info objectForKey:UIImagePickerControllerOriginalImage];


    if(ImageView.image == Nil)
    {
        [ImageView setImage:image];
    }
    else if(ImageView2.image == Nil)
    {
        [ImageView2 setImage:image];
    }

    [self dismissViewControllerAnimated:YES completion:NULL];
}
于 2013-05-24T11:41:37.787 回答