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