-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHousesTableViewController.swift
61 lines (49 loc) · 1.86 KB
/
HousesTableViewController.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
//
// HousesTableViewController.swift
// Westeros
//
// Created by yisus on 17/07/2017.
// Copyright © 2017 yisus. All rights reserved.
//
import UIKit
class HousesTableViewController: UITableViewController {
let model: [House]
init (model: [House]) {
self.model = model
super.init(nibName: nil, bundle: nil)
title = "Westeros"
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return model.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellID = "HouseCell"
// Descubrir cual es la casa que tenemos que mostrar
let house = model[indexPath.row]
// Crear una celda
var cell = tableView.dequeueReusableCell(withIdentifier: cellID)
if (cell == nil) {
// creamos a pelo
cell = UITableViewCell(style: .default, reuseIdentifier: cellID)
}
// sincronizar House -> Call
cell?.imageView?.image = house.sigil.image
cell?.textLabel?.text = house.name
return cell!
}
// MARK: - Table view delegate
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let house = model[indexPath.row]
let houseVC = HouseViewController(model: house)
navigationController?.pushViewController(houseVC, animated: true)
}
}