forked from venmo/Static
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewController.swift
More file actions
84 lines (69 loc) · 3.46 KB
/
ViewController.swift
File metadata and controls
84 lines (69 loc) · 3.46 KB
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
import UIKit
import Static
class ViewController: TableViewController {
// MARK: - Properties
private let customAccessory: UIView = {
let view = UIView(frame: CGRect(x: 0, y: 0, width: 32, height: 32))
view.backgroundColor = .red
return view
}()
// MARK: - Initializers
convenience init() {
self.init(style: .grouped)
}
// MARK: - UIViewController
override func viewDidLoad() {
super.viewDidLoad()
title = "Static"
tableView.rowHeight = 50
dataSource.sections = [
Section(header: "Styles", rows: [
Row(text: "Value 1", detailText: "Detail", cellClass: Value1Cell.self),
Row(text: "Value 1", detailText: "with an image", image: UIImage(named: "Settings"), cellClass: Value1Cell.self),
Row(text: "Value 2", detailText: "Detail", cellClass: Value2Cell.self),
Row(text: "Subtitle", detailText: "Detail", cellClass: SubtitleCell.self),
Row(text: "Button", detailText: "Detail", selection: { [unowned self] indexPath in
self.showAlert(title: "Row Selection")
}, cellClass: ButtonCell.self),
Row(text: "Custom from nib", cellClass: NibTableViewCell.self)
], footer: "This is a section footer."),
Section(header: "Accessories", rows: [
Row(text: "None"),
Row(text: "Disclosure Indicator", accessory: .disclosureIndicator),
Row(text: "Detail Disclosure Button", accessory: .detailDisclosureButton({ [unowned self] indexPath in
self.showAlert(title: "Detail Disclosure Button")
})),
Row(text: "Checkmark", accessory: .checkmark),
Row(text: "Detail Button", accessory: .detailButton({ [unowned self] indexPath in
self.showAlert(title: "Detail Button")
})),
Row(text: "Custom View", accessory: .view(customAccessory))
], footer: "Try tapping the ⓘ buttons."),
Section(header: "Selection", rows: [
Row(text: "Tap this row", selection: { [unowned self] indexPath in
self.showAlert(title: "Row Selection")
}),
Row(text: "Tap this row", selection: { [unowned self] indexPath in
let viewController = ViewController()
self.navigationController?.pushViewController(viewController, animated: true)
})
]),
Section(header: "Editing", rows: [
Row(text: "Swipe this row", editActions: [
Row.EditAction(title: "Warn", backgroundColor: .orange, selection: { [unowned self] indexPath in
self.showAlert(title: "Warned.")
}),
Row.EditAction(title: "Delete", style: .destructive, selection: { [unowned self] indexPath in
self.showAlert(title: "Deleted.")
})
])
])
]
}
// MARK: - Private
private func showAlert(title: String? = nil, message: String? = "You tapped it. Good work.", button: String = "Thanks") {
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: button, style: .cancel, handler: nil))
present(alert, animated: true, completion: nil)
}
}