From 5fbe87e25c1136e29494d181edbdbf6d6dbba6e1 Mon Sep 17 00:00:00 2001 From: Nicholas Tay Date: Wed, 16 Mar 2022 10:15:27 +1100 Subject: Add a detail view Resources: - https://guides.codepath.com/ios/Using-UITableView (was a bit dated) --- foray/Base.lproj/Main.storyboard | 84 ++++++++++++++++++++++++++++++++++- foray/ForayDetailViewController.swift | 33 ++++++++++++++ foray/ForayTableViewController.swift | 10 +++++ 3 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 foray/ForayDetailViewController.swift (limited to 'foray') diff --git a/foray/Base.lproj/Main.storyboard b/foray/Base.lproj/Main.storyboard index c5181ad..1212265 100644 --- a/foray/Base.lproj/Main.storyboard +++ b/foray/Base.lproj/Main.storyboard @@ -1,13 +1,14 @@ - + + - + @@ -56,6 +57,7 @@ + @@ -109,6 +111,7 @@ + @@ -118,14 +121,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/foray/ForayDetailViewController.swift b/foray/ForayDetailViewController.swift new file mode 100644 index 0000000..2e5cceb --- /dev/null +++ b/foray/ForayDetailViewController.swift @@ -0,0 +1,33 @@ +// +// ForayDetailViewController.swift +// foray +// +// Created by Nicholas Tay on 16/3/2022. +// + +import UIKit + +class ForayDetailViewController: UIViewController { + + var selectedItem: MyItem! + + @IBOutlet weak var titleLabel: UILabel! + @IBOutlet weak var imageView: UIImageView! + @IBOutlet weak var detailLabel: UILabel! + + override func viewDidLoad() { + super.viewDidLoad() + + titleLabel.text = selectedItem.name + imageView.image = UIImage(named: selectedItem.id) + switch selectedItem.type { + case .item: + detailLabel.text = "Item" + case .quest: + detailLabel.text = "Quest" + imageView.image = UIImage(named: "spy") + } + detailLabel.text! += " ID: " + selectedItem.id + } + +} diff --git a/foray/ForayTableViewController.swift b/foray/ForayTableViewController.swift index a5c367a..fd4854e 100644 --- a/foray/ForayTableViewController.swift +++ b/foray/ForayTableViewController.swift @@ -142,4 +142,14 @@ class ForayTableViewController: UITableViewController { dateFormatter.dateFormat = "yyyy" return "Released in " + dateFormatter.string(from: section.year) } + + // MARK: - Navigation + + override func prepare(for segue: UIStoryboardSegue, sender: Any?) { + let indexPath = tableView.indexPathForSelectedRow! + let item = self.sections[indexPath.section].items[indexPath.row] + + let dvc = segue.destination as! ForayDetailViewController + dvc.selectedItem = item + } } -- cgit