// // ForayTableViewController.swift // foray // // Created by Nicholas Tay on 14/3/2022. // import UIKit struct MyItem { var id: String var name: String } class ForayTableViewCell: UITableViewCell { @IBOutlet weak var cellItemName: UILabel! @IBOutlet weak var cellItemSubtitle: UILabel! @IBOutlet weak var cellItemImage: UIImageView! } class ForayTableViewController: UITableViewController { // MARK: - Static data TEMP let items = [ MyItem(id: "mh", name: "Miners Helmet"), MyItem(id: "it", name: "Inner Tube"), MyItem(id: "tbg", name: "Toboggan"), MyItem(id: "spy", name: "Spy Phone"), MyItem(id: "bnb", name: "Black Ninja Belt"), ] // MARK: - Table view data source override func numberOfSections(in tableView: UITableView) -> Int { // Returns number of sections for table return 1 } override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { // Returns number of rows for table return items.count } override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "ForayCell", for: indexPath) as! ForayTableViewCell let item = items[indexPath.row] cell.cellItemName?.text = item.name cell.cellItemSubtitle?.text = "Item ID: \(item.id)" cell.cellItemImage?.image = UIImage(named: item.id) return cell } override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { return "Section \(section)" } }