samedi 3 octobre 2020

multiple conditions if statement with logical and operator to Check multiple images != nil

I am trying to check if multiple UIImageView != nil using if statement and && operator but the problem is that when the user pick any photo of the 3 driverPImg.image != nil && passImg.image != nil && carImg.image != nil the next code exuted and it will not check for the rest conditions

extension VC: UINavigationControllerDelegate, UIImagePickerControllerDelegate {
    
    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
            
        if let editedImg = info[.editedImage] as? UIImage {
            
            SelectedImg = editedImg.withRenderingMode(.alwaysOriginal)
            
        } else if let originalImg = info[.originalImage] as? UIImage {
            SelectedImg = originalImg.withRenderingMode(.alwaysOriginal)
            
        }
        
        if let image = SelectedImg {
            if pictureSelectionType == .profilePicture {
                driverPImg.image = image
                
            }else if pictureSelectionType == .idPicture{
                passImg.image = image
                
            }else if pictureSelectionType == .vhiclePicture{
                carImg.image = image
                
            }else {
                backCarImg.image = image
                
            }

            if driverPImg.image != nil && passImg.image != nil && carImg.image != nil{
                sendApplyBtn.backgroundColor = UIColor.delevareColor
            }else {
                sendApplyBtn.backgroundColor = UIColor.lightGray
            }
            
            
        }
        dismiss(animated: true, completion: nil)
    }
        
    func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
        self.dismiss(animated: true, completion: nil)
    }
    
}

Aucun commentaire:

Enregistrer un commentaire