How to use multiple images in iOS with quick

I am creating a dating app. as you know, users need to register multiple photos in dating app.

so i got how to use 1 image picker in one view.

but I don't know how to add multiple image pickers.

I know I can only use one

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {  
}

      

and

func imagePickerControllerDidCancel(picker: UIImagePickerController) {
    picker.dismissViewControllerAnimated(false, completion:nil)
}

      

so I can't seem to find a solution for multiple imagepicker images.

my unsuccessful code is below.

import UIKit

class RegisterPicture : UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {


@IBAction func pick1(sender: AnyObject) {

    let picker1 = UIImagePickerController()

    picker1.sourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum

    picker1.allowsEditing = true

    picker1.delegate = self

    self.presentViewController(picker1, animated: false, completion: nil)
}

@IBAction func pick2(sender: AnyObject) {

    let picker2 = UIImagePickerController()

    picker2.sourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum

    picker2.allowsEditing = true

    picker2.delegate = self

    self.presentViewController(picker2, animated: false, completion: nil)
}

@IBOutlet var picture1: UIImageView!

@IBOutlet var picture2: UIImageView!

func imagePickerController(picker1: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {

    picker1.dismissViewControllerAnimated(false, completion : nil)
    self.picture1.image = info[UIImagePickerControllerOriginalImage] as? UIImage

}

func imagePickerController(picker2: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {

    picker2.dismissViewControllerAnimated(false, completion : nil)
    self.picture2.image = info[UIImagePickerControllerOriginalImage] as? UIImage

}


func imagePickerControllerDidCancel(picker1: UIImagePickerController) {

    picker1.dismissViewControllerAnimated(false, completion:nil)

}

func imagePickerControllerDidCancel(picker2: UIImagePickerController) {

    picker2.dismissViewControllerAnimated(false, completion:nil)

}
}

      

+1


source to share


3 answers


You cannot select more than one image with UIImagePickerController. You either have to make your own custom image picker that can or can be used by a third party such as one .



+3


source


I tried to find a UX-like iOS Photos App picker that is optimized to sync albums and assets, but I couldn't find such a controller, and finally I made my own. It is highly customizable and supports multiple selection, selective sorting and filtering, and is written entirely in modern Swift 3.0. If anyone finds a bug I will fix them for you :) You can try this link. https://github.com/DragonCherry/AssetsPickerViewController



+2


source


I used one image selection tool and then used combo boxes to determine what kind of image the user selected image gets.

enum selectableImage: String {
        case image1
        case image2
        case image3
    }

      

then on every call imagePickerController

I assign the variable var imageSelected = selectableImage.image1

like this. Then finally in imagePickerController

I used a switchable structure like this:

 func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {

        print("Inside imageController")

        print(info)
        // The info dictionary may contain multiple representations of the image. You want to use the original.

        guard let imagePicked = info[.originalImage] as? UIImage else {
            fatalError("Expected a dictionary containing an image, but was provided the following: \(info)")
        }

        // Set photoImageView to display the selected image.

        switch imageSelected {

        case selectableImage.image1:
             image1.image = imagePicked

        case selectableImage.image2:
             image2.image = imagePicked

        case selectableImage.image3:
            image3.image = imagePicked

        }


        // Dismiss the picker.
        dismiss(animated: true, completion: nil)
    }

      

Hope this helps.

0


source







All Articles