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.xcodeproj/project.pbxproj | 4 ++ foray/Base.lproj/Main.storyboard | 84 ++++++++++++++++++++++++++++++++++- foray/ForayDetailViewController.swift | 33 ++++++++++++++ foray/ForayTableViewController.swift | 10 +++++ 4 files changed, 129 insertions(+), 2 deletions(-) create mode 100644 foray/ForayDetailViewController.swift diff --git a/foray.xcodeproj/project.pbxproj b/foray.xcodeproj/project.pbxproj index 6df1a30..42e2a75 100644 --- a/foray.xcodeproj/project.pbxproj +++ b/foray.xcodeproj/project.pbxproj @@ -13,6 +13,7 @@ C04B45AD27DEF118001451A3 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C04B45AC27DEF118001451A3 /* Assets.xcassets */; }; C04B45B027DEF118001451A3 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C04B45AE27DEF118001451A3 /* LaunchScreen.storyboard */; }; C04B45B827DEF2ED001451A3 /* ForayTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C04B45B727DEF2ED001451A3 /* ForayTableViewController.swift */; }; + C0FEAF5F27E14C52000A7648 /* ForayDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0FEAF5E27E14C52000A7648 /* ForayDetailViewController.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -24,6 +25,7 @@ C04B45AF27DEF118001451A3 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; C04B45B127DEF118001451A3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; C04B45B727DEF2ED001451A3 /* ForayTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ForayTableViewController.swift; sourceTree = ""; }; + C0FEAF5E27E14C52000A7648 /* ForayDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ForayDetailViewController.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -59,6 +61,7 @@ C04B45A327DEF117001451A3 /* AppDelegate.swift */, C04B45A527DEF117001451A3 /* SceneDelegate.swift */, C04B45A927DEF117001451A3 /* Main.storyboard */, + C0FEAF5E27E14C52000A7648 /* ForayDetailViewController.swift */, C04B45B727DEF2ED001451A3 /* ForayTableViewController.swift */, C04B45AC27DEF118001451A3 /* Assets.xcassets */, C04B45AE27DEF118001451A3 /* LaunchScreen.storyboard */, @@ -139,6 +142,7 @@ buildActionMask = 2147483647; files = ( C04B45B827DEF2ED001451A3 /* ForayTableViewController.swift in Sources */, + C0FEAF5F27E14C52000A7648 /* ForayDetailViewController.swift in Sources */, C04B45A427DEF117001451A3 /* AppDelegate.swift in Sources */, C04B45A627DEF117001451A3 /* SceneDelegate.swift in Sources */, ); 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