From 0c7321e92313b594ab6ee600a214fa59fa2b56a2 Mon Sep 17 00:00:00 2001 From: Roopesh Chander Date: Sat, 13 Oct 2018 07:08:30 +0530 Subject: [PATCH] Use a split-view controller as the main (root) view controller --- WireGuard/WireGuard.xcodeproj/project.pbxproj | 6 +++- .../WireGuard/UI/iOS/MainViewController.swift | 12 +++++-- .../iOS/TunnelsListTableViewController.swift | 35 +++++++++++++++++++ 3 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift diff --git a/WireGuard/WireGuard.xcodeproj/project.pbxproj b/WireGuard/WireGuard.xcodeproj/project.pbxproj index 76cd451..e9d6dcc 100644 --- a/WireGuard/WireGuard.xcodeproj/project.pbxproj +++ b/WireGuard/WireGuard.xcodeproj/project.pbxproj @@ -9,6 +9,7 @@ /* Begin PBXBuildFile section */ 6F7774E1217181B1006A79B3 /* MainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F7774DF217181B1006A79B3 /* MainViewController.swift */; }; 6F7774E2217181B1006A79B3 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F7774E0217181B1006A79B3 /* AppDelegate.swift */; }; + 6F7774E421718281006A79B3 /* TunnelsListTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F7774E321718281006A79B3 /* TunnelsListTableViewController.swift */; }; 6FF4AC1F211EC472002C96EB /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6FF4AC1E211EC472002C96EB /* Assets.xcassets */; }; 6FF4AC22211EC472002C96EB /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 6FF4AC20211EC472002C96EB /* LaunchScreen.storyboard */; }; 6FF4AC472120B9E0002C96EB /* NetworkExtension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6FF4AC462120B9E0002C96EB /* NetworkExtension.framework */; }; @@ -17,6 +18,7 @@ /* Begin PBXFileReference section */ 6F7774DF217181B1006A79B3 /* MainViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MainViewController.swift; sourceTree = ""; }; 6F7774E0217181B1006A79B3 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 6F7774E321718281006A79B3 /* TunnelsListTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TunnelsListTableViewController.swift; sourceTree = ""; }; 6FF4AC14211EC46F002C96EB /* WireGuard.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = WireGuard.app; sourceTree = BUILT_PRODUCTS_DIR; }; 6FF4AC1E211EC472002C96EB /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 6FF4AC21211EC472002C96EB /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; @@ -49,8 +51,9 @@ 6F7774DE217181B1006A79B3 /* iOS */ = { isa = PBXGroup; children = ( - 6F7774DF217181B1006A79B3 /* MainViewController.swift */, 6F7774E0217181B1006A79B3 /* AppDelegate.swift */, + 6F7774DF217181B1006A79B3 /* MainViewController.swift */, + 6F7774E321718281006A79B3 /* TunnelsListTableViewController.swift */, ); path = iOS; sourceTree = ""; @@ -168,6 +171,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 6F7774E421718281006A79B3 /* TunnelsListTableViewController.swift in Sources */, 6F7774E2217181B1006A79B3 /* AppDelegate.swift in Sources */, 6F7774E1217181B1006A79B3 /* MainViewController.swift in Sources */, ); diff --git a/WireGuard/WireGuard/UI/iOS/MainViewController.swift b/WireGuard/WireGuard/UI/iOS/MainViewController.swift index a296b5f..4672c27 100644 --- a/WireGuard/WireGuard/UI/iOS/MainViewController.swift +++ b/WireGuard/WireGuard/UI/iOS/MainViewController.swift @@ -8,8 +8,16 @@ import UIKit -class MainViewController: UIViewController { +class MainViewController: UISplitViewController { override func loadView() { - self.view = UIView() + let detailVC = UIViewController() + let detailNC = UINavigationController(rootViewController: detailVC) + + let masterVC = TunnelsListTableViewController() + let masterNC = UINavigationController(rootViewController: masterVC) + + self.viewControllers = [ masterNC, detailNC ] + + super.loadView() } } diff --git a/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift b/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift new file mode 100644 index 0000000..e886e4a --- /dev/null +++ b/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift @@ -0,0 +1,35 @@ +// +// TunnelsListTableViewController.swift +// WireGuard +// +// Created by Roopesh Chander on 12/10/18. +// Copyright © 2018 Roopesh Chander. All rights reserved. +// + +import UIKit + +class TunnelsListTableViewController: UITableViewController { + + override func viewDidLoad() { + super.viewDidLoad() + self.title = "WireGuard" + let addButtonItem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(addButtonTapped(sender:))) + self.navigationItem.rightBarButtonItem = addButtonItem + } + + @objc func addButtonTapped(sender: UIBarButtonItem!) { + print("Add button tapped") + } +} + +// MARK: UITableViewDataSource + +extension TunnelsListTableViewController { + override func numberOfSections(in tableView: UITableView) -> Int { + return 0 + } + + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return 0 + } +}