无法在uiImageViewPickerController中选择Imageview2

时间:2018-07-25 17:57:19

标签: ios uiimagepickercontroller

我正在将4 UIImageViewUIImagePickerController一起使用。我想使用相机拍摄在imageview 1中显示的照片,然后再次拍摄我想在imageview 2中显示的照片,但是问题是如果我再次拍摄也仅在Imageview1中显示的照片。

这里是我的代码

 @IBOutlet weak var CameraOutlet: UIButton!
 @IBOutlet weak var Complaint_Image1: UIImageView!
 @IBOutlet weak var Complaint_Image2: UIImageView!
 @IBOutlet weak var Complaint_Image3: UIImageView!
 @IBOutlet weak var Complaint_Image4: UIImageView!

func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
    dismiss(animated: true, completion: nil)
}

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
    let picture = info[UIImagePickerControllerOriginalImage] as! UIImage
    Complaint_Image1.image = picture

    if Complaint_Image1 != nil {
        Complaint_Image2.image = picture
    }

    dismiss(animated: true, completion: nil)
}

1 个答案:

答案 0 :(得分:0)

您的逻辑应该是:

  1. 如果image1.image没有图像,则设置该图像
  2. 否则,设置image2.image。

这些行:

Complaint_Image1.image = picture

if Complaint_Image1 != nil {
    Complaint_Image2.image = picture
}

应该是

if Complaint_Image1.image != nil {
    Complaint_Image2.image = picture
} else {
    Complaint_Image1.image = picture
}