blob: 359fcfeb7b9e1142441ce915ea29b9aa2ff3eb1d (
plain) (
blame)
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
|
// SPDX-License-Identifier: MIT
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
import UIKit
class MainViewController: UISplitViewController {
var tunnelsListVC: TunnelsListTableViewController?
init() {
let detailVC = UIViewController()
detailVC.view.backgroundColor = UIColor.white
let detailNC = UINavigationController(rootViewController: detailVC)
let masterVC = TunnelsListTableViewController()
let masterNC = UINavigationController(rootViewController: masterVC)
self.tunnelsListVC = masterVC
super.init(nibName: nil, bundle: nil)
self.viewControllers = [ masterNC, detailNC ]
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
self.delegate = self
// On iPad, always show both masterVC and detailVC, even in portrait mode, like the Settings app
self.preferredDisplayMode = .allVisible
}
}
extension MainViewController: UISplitViewControllerDelegate {
func splitViewController(_ splitViewController: UISplitViewController,
collapseSecondary secondaryViewController: UIViewController,
onto primaryViewController: UIViewController) -> Bool {
// On iPhone, if the secondaryVC (detailVC) is just a UIViewController, it indicates that it's empty,
// so just show the primaryVC (masterVC).
let detailVC = (secondaryViewController as? UINavigationController)?.viewControllers.first
let isDetailVCEmpty: Bool
if let detailVC = detailVC {
isDetailVCEmpty = (type(of: detailVC) == UIViewController.self)
} else {
isDetailVCEmpty = true
}
return isDetailVCEmpty
}
}
|