-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathDetailViewController.swift
77 lines (64 loc) · 2.22 KB
/
DetailViewController.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
//
// DetailViewController.swift
// SoF-MedList
//
// Created by Pascal Pfiffner on 6/20/14.
// Copyright (c) 2014 SMART Platforms. All rights reserved.
//
import UIKit
import SMART
class DetailViewController: UIViewController, UISplitViewControllerDelegate {
@IBOutlet var detailDescriptionLabel: UILabel?
/// The prescription to show details about
var resource: Resource? {
didSet {
configureView()
}
}
func configureView() {
guard let label = detailDescriptionLabel else {
return
}
if let detail = resource {
do {
let data = try JSONSerialization.data(withJSONObject: detail.asJSON(), options: .prettyPrinted)
let string = String(data: data, encoding: String.Encoding.utf8)
label.text = string ?? "Unable to generate JSON"
}
catch let error {
label.text = "\(error)"
}
}
else {
var style = UIFont.TextStyle.headline
if #available(iOS 9, *) {
style = .title1
}
let p = NSMutableParagraphStyle()
p.alignment = .center
p.paragraphSpacingBefore = 200.0
let attr = NSAttributedString(string: "Select a FHIR Resource first", attributes: [
NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: style),
NSAttributedString.Key.paragraphStyle: p,
])
label.attributedText = attr
}
}
override func viewDidLoad() {
super.viewDidLoad()
configureView()
}
// MARK: - Split view
func splitViewController(_ splitController: UISplitViewController, willShow viewController: UIViewController, invalidating barButtonItem: UIBarButtonItem) {
// Called when the view is shown again in the split view, invalidating the button and popover controller.
self.navigationItem.setLeftBarButton(nil, animated: true)
}
func splitViewController(_ splitController: UISplitViewController, collapseSecondary secondaryViewController: UIViewController, onto primaryViewController: UIViewController) -> Bool {
// Return true to indicate that we have handled the collapse by doing nothing; the secondary controller will be discarded.
return true
}
func splitViewController(_ splitViewController: UISplitViewController, separateSecondaryFrom primaryViewController: UIViewController) -> UIViewController? {
// We want ourselves to be separated
return self
}
}