-2

I'm making an app where the user selects a football lineup, then selects 11 football player images from a gallery, and then drags those images into positions. Since I need to select 11 photos at once, I decided to use FPikker, but I can only display the same image in all 11 positions. I know that you can display different images using a Collection, but I need to place each image in a View so that they can be moved around.This is the part of my code where the PHPickerViewController works

After selecting images they just cycle through and then display the last selected photo, I tried to find information on the internet but I only found options with CollectionView and they don't suit me

3
  • 4
    Do not post pictures of code. edit your question to include relevant code in a code block, but you are obviously assigning the same image to all of your image views. Commented Aug 8, 2024 at 11:31
  • You should have your image view outlets on an array. That will make it easier for you Commented Aug 8, 2024 at 11:36
  • The title needs to be written in English Commented Aug 8, 2024 at 13:17

1 Answer 1

1

Right now you are setting every imageView the same image, which is why you always have the same image in every imageView.

Instead you could do something like this.

EDIT: Also I think you need to call dismiss on the picker instead of the view controller.

func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {
    picker.dismiss(animated: true, completion: nil)

    var index = 0

    for item in results {
        item.itemProvider.loadObject(ofClass: UIImage.self) { image, _ in
            guard let image = image as? UIImage else {
                return
            }

            DispatchQueue.main.async { [weak self] in
                guard let self else { return }

                if index == 0 {
                    self.fImgOne.image = image
                } else if index == 1 {
                    self.fImgTwo.image = image
                } else if index == 2 {
                    self.fImgThree.image = image
                } else if index == 3 {
                    self.fImgFour.image = image
                } else if index == 4 {
                    self.fImgFive.image = image
                } else if index == 5 {
                    self.fImgSix.image = image
                } else if index == 6 {
                    self.fImgSeven.image = image
                } else if index == 7 {
                    self.fImgEight.image = image
                } else if index == 8 {
                    self.fImgNine.image = image
                } else if index == 9 {
                    self.fImgTen.image = image
                } else if index == 10 {
                    self.fImgEleven.image = image
                }
                index += 1
            }
        }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.