-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathFeedTableViewController.swift
93 lines (56 loc) · 2 KB
/
FeedTableViewController.swift
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//
// FeedTableViewController.swift
// Ecommerce
//
// Created by Eric Rosas on 2/13/17.
// Copyright © 2017 EmpireAppDesignz. All rights reserved.
//
import UIKit
class FeedTableViewController : UITableViewController
{
var shoes: [Shoe]?
struct Storyboard {
static let feedShoeCell = "FeedShoeCell"
static let showShoeDetail = "ShowShoeDetail"
}
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.title = "FEED"
shoes = Shoe.fetchShoes()
self.tableView.reloadData()
self.tableView.estimatedRowHeight = tableView.rowHeight
self.tableView.rowHeight = UITableView.automaticDimension
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == Storyboard.showShoeDetail {
if let shoeDetailTVC = segue.destination as? ShoeDetailTableViewController {
let selectedShoe = self.shoes?[(sender as! IndexPath).row]
shoeDetailTVC.shoe = selectedShoe
}
}
}
}
// MARK - UITableViewDataSource
extension FeedTableViewController
{
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if let shoes = shoes {
return shoes.count
} else {
return 0
}
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: Storyboard.feedShoeCell, for: indexPath) as! FeedShoeTableViewCell
cell.shoe = self.shoes?[indexPath.row]
cell.selectionStyle = .none
return cell
}
}
// MARK: - UITableViewDelegate
extension FeedTableViewController
{
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
self.performSegue(withIdentifier: Storyboard.showShoeDetail, sender: indexPath)
}
}