forked from zhiphe/Potatso-iOS
-
Notifications
You must be signed in to change notification settings - Fork 1
/
RequestDetailViewController.swift
105 lines (85 loc) · 2.92 KB
/
RequestDetailViewController.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//
// RequestDetailViewController.swift
// Potatso
//
// Created by LEI on 4/26/16.
// Copyright © 2016 TouchingApp. All rights reserved.
//
import Foundation
import Cartography
let kDetailRawTextCellIdentifier = "rawText"
protocol RequestDetailCell {
func config(request: Request, event: RequestEvent)
}
extension RequestEventType {
var cellIdentifier: String {
switch self {
case .Init:
return kDetailRawTextCellIdentifier
default:
return kDetailRawTextCellIdentifier
}
}
}
class RequestDetailViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
let request: Request
let requestEvents: [RequestEvent]
init(request: Request) {
self.request = request
self.requestEvents = request.events
super.init(nibName: nil, bundle: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.title = "Request Detail".localized()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return requestEvents.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let event = requestEvents[indexPath.row]
let cell = tableView.dequeueReusableCellWithIdentifier(event.type.cellIdentifier, forIndexPath: indexPath)
if let c = cell as? RequestDetailCell {
c.config(request, event: event)
}
cell.selectionStyle = .None
return cell
}
override func loadView() {
super.loadView()
view.backgroundColor = Color.Background
view.addSubview(leftHintView)
view.addSubview(tableView)
tableView.registerClass(RequestDetailRawTextCell.self, forCellReuseIdentifier: kDetailRawTextCellIdentifier)
setupLayout()
}
func setupLayout() {
constrain(tableView, leftHintView, view) { tableView, leftHintView, view in
tableView.edges == view.edges
leftHintView.width == 4
leftHintView.top == view.top
leftHintView.bottom == view.bottom
leftHintView.centerX == view.leading + 15
}
}
lazy var tableView: UITableView = {
let v = UITableView(frame: CGRect.zero, style: .Plain)
v.dataSource = self
v.delegate = self
v.tableFooterView = UIView()
v.tableHeaderView = UIView()
v.separatorStyle = .None
v.estimatedRowHeight = 110
v.rowHeight = UITableViewAutomaticDimension
v.backgroundColor = UIColor.clearColor()
return v
}()
lazy var leftHintView: UIView = {
let v = UIView()
v.backgroundColor = "E8E8E8".color
return v
}()
}