ImageCollectionViewController

class ImageCollectionViewController : UICollectionViewController

Undocumented

  • An array of UIImage objects to display.

    Declaration

    Swift

    var images: [UIImage]
  • A label that apppears if there are no images.

    Todo

    use closure syntax to set it up at declaration

    Todo

    make private and lazy

    Declaration

    Swift

    var noImagesLabel: UILabel
  • The currently selected index.

    This is mainly used for interactions with a ImagePagingCollectionViewController

    Declaration

    Swift

    var currentIndex: Int
  • The Plant object whose images are being displayed.

    Declaration

    Swift

    var plant: Plant!
  • An object that manages the array of Plant objects.

    Declaration

    Swift

    var plantsManager: PlantsManager!
  • The number of images in a row

    Todo

    make private

    Declaration

    Swift

    let numberOfImagesPerRow: CGFloat
  • The spacing between images.

    Todo

    make private

    Declaration

    Swift

    let spacingBetweenCells: CGFloat
  • A boolean indicating whether multiple cells be selected. The selected images can then be shared or deleted.

    Todo

    make private

    Declaration

    Swift

    var inMultiSelectMode: Bool { get set }
  • Indices of selected images.

    Todo

    make private

    Declaration

    Swift

    var selectedImageIndices: [Int]
  • The standard title to use when not in multi-select mode (inMultiSelectMode == false). It is set to the same String as self.title in viewDidLoad().

    Declaration

    Swift

    var standardTitle: String?
  • Undocumented

    Declaration

    Swift

    override func viewDidLoad()
  • Load the images of a plant into images: [UIImage]. It is called once during set up and when the user is done selecting new images.

    Todo

    experiment with loading the images in cellForRowAt:

    Todo

    make private

    Declaration

    Swift

    func loadImages()
  • Undocumented

    Declaration

    Swift

    override func viewWillAppear(_ animated: Bool)
  • Undocumented

    Declaration

    Swift

    override func viewWillDisappear(_ animated: Bool)
  • An action sheet is presented to imort or edit images.

    Declaration

    Swift

    @objc
    func editButtonTapped()
  • Undocumented

    Declaration

    Swift

    override func numberOfSections(in collectionView: UICollectionView) -> Int
  • Undocumented

    Declaration

    Swift

    override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
  • Undocumented

    Declaration

    Swift

    override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
  • Undocumented

    Declaration

    Swift

    override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)
  • Undocumented

    Declaration

    Swift

    override func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath)
  • Organize the tool bar for multi-select mode. The tool bar will have a trash and a share icons for deleting or sharing images.

    Declaration

    Swift

    func setupToolbar()
  • Called to turn on miltu-select mode by setting inMultiSelectMode to true.

    Declaration

    Swift

    @objc
    func selectMultipleImages(_ alert: UIAlertAction)

    Parameters

    alert

    The alert action that called the function (not used).

  • Delete the currently selected images. The images are deleted from images: [UIImage], the plant.images: [String], removed from disk And from the collection view. The deletion is animated by calling collectionView.deleteItems(at: [IndexPath]).

    Declaration

    Swift

    @objc
    func deleteSelectedImages(_ alert: UIAlertAction)

    Parameters

    alert

    The alert action that called the function (not used).

  • Share the currently selected images using the satandard UIActivityViewController(activityItems:applicationActivities:).

    Declaration

    Swift

    @objc
    func shareSelectedImages(_ alert: UIAlertAction)

    Parameters

    alert

    The alert action that called the function (not used).

  • Deactivate multi-select mode by setting inMultiSelectMode to false.

    Declaration

    Swift

    @objc
    func exitMultiSelectionMode(_ alert: UIAlertAction)
  • Respond to a change in index of the current image when in the paging view.

    Todo

    change name of first parameter to imagePagingCollectionViewController

    Declaration

    Swift

    func containerViewController(_ containerViewController: ImagePagingCollectionViewController, indexDidChangeTo currentIndex: Int)

    Parameters

    containerViewController

    The view controller that called the function.

    currentIndex

    The index of the paging view controller. self.currentIndex is assigned this value to stay in sync.

  • A notification from the ImagePagingCollectionViewController to delete the image at an index.

    Note

    The image is already deleted from the plant, erased from disk, and removed from images: [UIImage]. The only task to be done, here, is to remove the image from the collection view using collectionView.deleteItems(at: [IndexPath]).

    Todo

    add first paramter as _ containerViewController: ImagePagingCollectionViewController

    Declaration

    Swift

    func removeCell(at index: Int)

    Parameters

    index

    Index at which to delete the image.

  • Set the profile or the plant: Plant using the image at the specified index of images: [UIImage].

    Declaration

    Swift

    func setProfileAs(imageAt index: Int)

    Parameters

    index

    index of images: [UIImage] for which to pull the image for the profile image.

  • Delete an image from plant: Plant at the specific index.

    Declaration

    Swift

    func deleteImage(at index: Int)

    Parameters

    index

    index of images: [UIImage] and the plant: Plant object’s image array.

  • Save changes to an image at the specific index.

    Note

    The image is replaced, not appended. Therefore, it retains the same file name and UUID. Therefore, anything that references this image (eg. the header image) will be affected by the change.

    Declaration

    Swift

    func save(image: UIImage, withIndex index: Int)

    Parameters

    image

    The new (edited) image to replace the old one with.

    index

    The index of the image being replaced.