PlantLibraryTableViewController
class PlantLibraryTableViewController : UITableViewController
The view controller for the main table view of the Library collection. Each row is a different plant that can
be selected to see detailed information. Swiping to delete is enabled. A new plant can be added through
a navigation bar button (+
).
-
An object that manages the array of
Plant
objects.Declaration
Swift
var plantsManager: PlantsManager
-
Array of all of the icon images.
Declaration
Swift
var iconImages: [Plant : UIImage]
-
The index of the last selected row. Is
nil
if no row has been selected.Declaration
Swift
var lastSelectedRow: Int?
-
Undocumented
Declaration
Swift
override func viewDidLoad()
-
Undocumented
Declaration
Swift
override func viewWillAppear(_ animated: Bool)
-
Undocumented
Declaration
Swift
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
-
Undocumented
Declaration
Swift
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
-
Undocumented
Declaration
Swift
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
-
If the plant has an icon stored, use that. Otherwise a new one if made (and saved) from the header image. If there are no images for the plant, the default image is used.
Declaration
Swift
func getPlantIcons()
-
Insert a new plant.
It begins with no name or data and the detail view is automatically pushed.
Declaration
Swift
@objc func addNewPlant()
-
If the plant has an icon stored, use that. Otherwise a new one if made (and saved) from the header image. If there are no images for the plant, the default image is used.
Todo
This looks very simillar to
getPlantIcons()
- they can likely be combined.Declaration
Swift
func setIcon(for plant: Plant)
Parameters
plant
Plant object to set an icon for.
-
The function for creating an icon.
The final size is 60 x 60 pixels.
resizeForIcon(image:) -> UIImage
is used for the copping and resizing.Declaration
Swift
func makeNewIconFor(plant: Plant, withImage image: UIImage) -> UIImage
Parameters
plant
Plant object to set an icon for.
image
The image to use for the icon.
-
Make an image the correct size for an icon.
Declaration
Swift
func resizeForIcon(image: UIImage) -> UIImage
Parameters
image
Image to resize.
-
Undocumented
Declaration
Swift
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath)
-
Undocumented
Declaration
Swift
override func prepare(for segue: UIStoryboardSegue, sender: Any?)
-
Undocumented
Declaration
Swift
@IBAction func unwindToLibraryTableView(_ unwindSegue: UIStoryboardSegue)