aboutsummaryrefslogtreecommitdiff
path: root/foray
diff options
context:
space:
mode:
authorNicholas Tay <nick@windblume.net>2022-03-18 14:04:12 +1100
committerNicholas Tay <nick@windblume.net>2022-03-18 14:04:51 +1100
commitf45d90ba504496e68d6a4cb2f7f887c011e9b19d (patch)
treea201aa4fa16a24d8538eb865bcb7fcfdafe27f2a /foray
parent16d2dc26ac31f2c5ec3dfd72228d2e7997459028 (diff)
downloadforayios-f45d90ba504496e68d6a4cb2f7f887c011e9b19d.tar.gz
forayios-f45d90ba504496e68d6a4cb2f7f887c011e9b19d.tar.bz2
forayios-f45d90ba504496e68d6a4cb2f7f887c011e9b19d.zip
Split table view cell into separate file
Cell no longer uses prototypes as registered in the Storyboard. Instead is a custom class inheriting the UITableViewCell and is manually registered by the VC. This is a first step towards reimplementing the prototype cells. Only has one label at the moment.
Diffstat (limited to '')
-rw-r--r--foray.xcodeproj/project.pbxproj4
-rw-r--r--foray/ForayNewTableViewCell.swift39
-rw-r--r--foray/ForayTableViewController.swift27
3 files changed, 60 insertions, 10 deletions
diff --git a/foray.xcodeproj/project.pbxproj b/foray.xcodeproj/project.pbxproj
index 222f951..50615ca 100644
--- a/foray.xcodeproj/project.pbxproj
+++ b/foray.xcodeproj/project.pbxproj
@@ -14,6 +14,7 @@
C04B45B027DEF118001451A3 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C04B45AE27DEF118001451A3 /* LaunchScreen.storyboard */; };
C04B45B827DEF2ED001451A3 /* ForayTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C04B45B727DEF2ED001451A3 /* ForayTableViewController.swift */; };
C04EDE4227E428AB00D83005 /* SnapKit in Frameworks */ = {isa = PBXBuildFile; productRef = C04EDE4127E428AB00D83005 /* SnapKit */; };
+ C04EDE4427E4298D00D83005 /* ForayNewTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = C04EDE4327E4298D00D83005 /* ForayNewTableViewCell.swift */; };
C0FEAF5F27E14C52000A7648 /* ForayDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0FEAF5E27E14C52000A7648 /* ForayDetailViewController.swift */; };
/* End PBXBuildFile section */
@@ -26,6 +27,7 @@
C04B45AF27DEF118001451A3 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
C04B45B127DEF118001451A3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
C04B45B727DEF2ED001451A3 /* ForayTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ForayTableViewController.swift; sourceTree = "<group>"; };
+ C04EDE4327E4298D00D83005 /* ForayNewTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ForayNewTableViewCell.swift; sourceTree = "<group>"; };
C0FEAF5E27E14C52000A7648 /* ForayDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ForayDetailViewController.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
@@ -65,6 +67,7 @@
C04B45A927DEF117001451A3 /* Main.storyboard */,
C0FEAF5E27E14C52000A7648 /* ForayDetailViewController.swift */,
C04B45B727DEF2ED001451A3 /* ForayTableViewController.swift */,
+ C04EDE4327E4298D00D83005 /* ForayNewTableViewCell.swift */,
C04B45AC27DEF118001451A3 /* Assets.xcassets */,
C04B45AE27DEF118001451A3 /* LaunchScreen.storyboard */,
C04B45B127DEF118001451A3 /* Info.plist */,
@@ -151,6 +154,7 @@
files = (
C04B45B827DEF2ED001451A3 /* ForayTableViewController.swift in Sources */,
C0FEAF5F27E14C52000A7648 /* ForayDetailViewController.swift in Sources */,
+ C04EDE4427E4298D00D83005 /* ForayNewTableViewCell.swift in Sources */,
C04B45A427DEF117001451A3 /* AppDelegate.swift in Sources */,
C04B45A627DEF117001451A3 /* SceneDelegate.swift in Sources */,
);
diff --git a/foray/ForayNewTableViewCell.swift b/foray/ForayNewTableViewCell.swift
new file mode 100644
index 0000000..b2b22af
--- /dev/null
+++ b/foray/ForayNewTableViewCell.swift
@@ -0,0 +1,39 @@
+//
+// ForayNewTableViewCell.swift
+// foray
+//
+// Created by Nicholas Tay on 18/3/2022.
+//
+
+import UIKit
+import SnapKit
+
+class ForayNewTableViewCell: UITableViewCell {
+
+ let nameLabel: UILabel = UILabel()
+
+ override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
+ super.init(style: style, reuseIdentifier: reuseIdentifier)
+ initialiseViews()
+ }
+
+ required init?(coder: NSCoder) {
+ fatalError("unreachable")
+ }
+
+ private func initialiseViews() {
+ contentView.addSubview(nameLabel)
+ setupConstraints()
+ }
+
+ private func setupConstraints() {
+ nameLabel.snp.makeConstraints { (make) in
+ make.top.bottom.equalToSuperview().inset(8)
+ make.leading.trailing.equalToSuperview().inset(8)
+ }
+ }
+
+ public func setData(str: String) {
+ nameLabel.text = str
+ }
+}
diff --git a/foray/ForayTableViewController.swift b/foray/ForayTableViewController.swift
index ae8ff25..8f11285 100644
--- a/foray/ForayTableViewController.swift
+++ b/foray/ForayTableViewController.swift
@@ -55,6 +55,9 @@ class ForayTableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
+ // Register our custom cell
+ tableView.register(ForayNewTableViewCell.self, forCellReuseIdentifier: "ForayNewTableViewCell")
+
// Not sure if this is the right way to go about this...
let alert = UIAlertController(title: nil, message: "Grabbing data...", preferredStyle: .alert)
let loadingIndicator = UIActivityIndicatorView(frame: CGRect(x: 10, y: 5, width: 50, height: 50))
@@ -149,17 +152,21 @@ class ForayTableViewController: UITableViewController {
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let item = self.sections[indexPath.section].items[indexPath.row]
- let cell: ForayTableViewCell
- switch item.type {
- case .item:
- cell = tableView.dequeueReusableCell(withIdentifier: "ForayCell", for: indexPath) as! ForayTableViewCell
- cell.cellItemImage?.image = UIImage(named: item.id)
- case .quest:
- cell = tableView.dequeueReusableCell(withIdentifier: "ForayQuestCell", for: indexPath) as! ForayTableViewCell
- }
- cell.cellItemName?.text = item.name
- cell.cellItemSubtitle?.text = "ID: " + item.id
+// let cell: ForayTableViewCell
+// switch item.type {
+// case .item:
+// cell = tableView.dequeueReusableCell(withIdentifier: "ForayCell", for: indexPath) as! ForayTableViewCell
+// cell.cellItemImage?.image = UIImage(named: item.id)
+// case .quest:
+// cell = tableView.dequeueReusableCell(withIdentifier: "ForayQuestCell", for: indexPath) as! ForayTableViewCell
+// }
+//
+// cell.cellItemName?.text = item.name
+// cell.cellItemSubtitle?.text = "ID: " + item.id
+
+ let cell: ForayNewTableViewCell = tableView.dequeueReusableCell(withIdentifier: "ForayNewTableViewCell", for: indexPath) as! ForayNewTableViewCell
+ cell.setData(str: item.name)
return cell
}