1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
//
// 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)"
}
}
|