forked from turbolinks/turbolinks-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDemoViewController.swift
31 lines (27 loc) · 1006 Bytes
/
DemoViewController.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
import Turbolinks
import UIKit
class DemoViewController: Turbolinks.VisitableViewController {
lazy var errorView: ErrorView = {
let view = Bundle.main.loadNibNamed("ErrorView", owner: self, options: nil)!.first as! ErrorView
view.translatesAutoresizingMaskIntoConstraints = false
view.retryButton.addTarget(self, action: #selector(retry(_:)), for: .touchUpInside)
return view
}()
func presentError(_ error: Error) {
errorView.error = error
view.addSubview(errorView)
installErrorViewConstraints()
}
func installErrorViewConstraints() {
view.addConstraints(
NSLayoutConstraint.constraints(
withVisualFormat: "H:|[view]|", options: [], metrics: nil, views: ["view": errorView]))
view.addConstraints(
NSLayoutConstraint.constraints(
withVisualFormat: "V:|[view]|", options: [], metrics: nil, views: ["view": errorView]))
}
@objc func retry(_ sender: AnyObject) {
errorView.removeFromSuperview()
reloadVisitable()
}
}