aboutsummaryrefslogtreecommitdiff
path: root/foray
diff options
context:
space:
mode:
Diffstat (limited to 'foray')
-rw-r--r--foray/ForayNewTableViewCell.swift39
-rw-r--r--foray/ForayTableViewController.swift27
2 files changed, 56 insertions, 10 deletions
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
}