Fix detail navigation controller code

This commit is contained in:
Maurice Parker 2019-07-18 18:49:27 -05:00
parent d01f356869
commit b5411cde42
4 changed files with 44 additions and 13 deletions

View File

@ -207,9 +207,8 @@ class AppCoordinator: UndoableCommandRunner {
rootSplitViewController.delegate = self rootSplitViewController.delegate = self
masterNavigationController = (rootSplitViewController.viewControllers.first as! UINavigationController) masterNavigationController = (rootSplitViewController.viewControllers.first as! UINavigationController)
masterFeedViewController = UIStoryboard.main.instantiateController(ofType: MasterFeedViewController.self) masterFeedViewController = (masterNavigationController.topViewController as! MasterFeedViewController)
masterFeedViewController.coordinator = self masterFeedViewController.coordinator = self
masterNavigationController.pushViewController(masterFeedViewController, animated: false)
// let detailNavigationController = (rootSplitViewController.viewControllers.last as! UINavigationController) // let detailNavigationController = (rootSplitViewController.viewControllers.last as! UINavigationController)
// detailNavigationController.topViewController!.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem // detailNavigationController.topViewController!.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem
@ -447,17 +446,18 @@ class AppCoordinator: UndoableCommandRunner {
} }
func selectArticle(_ indexPath: IndexPath) { func selectArticle(_ indexPath: IndexPath) {
if let detailNavController = rootSplitViewController.viewControllers.last as? UINavigationController, if let detailNavigationController = rootSplitViewController.viewControllers.last as? UINavigationController,
let _ = detailNavController.topViewController as? DetailViewController { let _ = detailNavigationController.topViewController as? DetailViewController {
currentArticleIndexPath = indexPath currentArticleIndexPath = indexPath
} else { } else {
let detailViewController = UIStoryboard.main.instantiateController(ofType: DetailViewController.self) let detailNavigationController = UIStoryboard.main.instantiateViewController(identifier: "DetailNavigationController") as! UINavigationController
let detailViewController = detailNavigationController.topViewController as! DetailViewController
detailViewController.coordinator = self detailViewController.coordinator = self
detailViewController.navigationItem.leftBarButtonItem = rootSplitViewController.displayModeButtonItem detailViewController.navigationItem.leftBarButtonItem = rootSplitViewController.displayModeButtonItem
detailViewController.navigationItem.leftItemsSupplementBackButton = true detailViewController.navigationItem.leftItemsSupplementBackButton = true
currentArticleIndexPath = indexPath currentArticleIndexPath = indexPath
// rootSplitViewController.toggleMasterView() // rootSplitViewController.toggleMasterView()
rootSplitViewController.showDetailViewController(detailViewController, sender: self) rootSplitViewController.showDetailViewController(detailNavigationController, sender: self)
} }
} }

View File

@ -19,6 +19,9 @@
<rect key="frame" x="0.0" y="813" width="414" height="49"/> <rect key="frame" x="0.0" y="813" width="414" height="49"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
</toolbar> </toolbar>
<connections>
<segue destination="7bK-jq-Zjz" kind="relationship" relationship="rootViewController" id="Ehy-DL-bQz"/>
</connections>
</navigationController> </navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="8fS-aE-onr" sceneMemberID="firstResponder"/> <placeholder placeholderIdentifier="IBFirstResponder" id="8fS-aE-onr" sceneMemberID="firstResponder"/>
</objects> </objects>
@ -33,7 +36,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews> <subviews>
<wkWebView opaque="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="t8d-md-Yhc"> <wkWebView opaque="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="t8d-md-Yhc">
<rect key="frame" x="0.0" y="44" width="414" height="769"/> <rect key="frame" x="0.0" y="88" width="414" height="725"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<wkWebViewConfiguration key="configuration"> <wkWebViewConfiguration key="configuration">
<audiovisualMediaTypes key="mediaTypesRequiringUserActionForPlayback" none="YES"/> <audiovisualMediaTypes key="mediaTypesRequiringUserActionForPlayback" none="YES"/>
@ -134,7 +137,23 @@
</viewController> </viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="FJe-Yq-33r" sceneMemberID="firstResponder"/> <placeholder placeholderIdentifier="IBFirstResponder" id="FJe-Yq-33r" sceneMemberID="firstResponder"/>
</objects> </objects>
<point key="canvasLocation" x="900" y="-23"/> <point key="canvasLocation" x="2367" y="-83"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="MFb-g9-xHT">
<objects>
<navigationController storyboardIdentifier="SystemMessageNavigationController" id="mTc-f9-2dr" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="Ork-ch-DOU">
<rect key="frame" x="0.0" y="44" width="414" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<connections>
<segue destination="Xld-e9-xoL" kind="relationship" relationship="rootViewController" id="E2B-jI-ffd"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="WCE-Jg-o7b" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="154" y="-83"/>
</scene> </scene>
<!--System Message--> <!--System Message-->
<scene sceneID="tbo-yR-QVH"> <scene sceneID="tbo-yR-QVH">
@ -158,6 +177,7 @@
</constraints> </constraints>
<viewLayoutGuide key="safeArea" id="zOb-OV-HXy"/> <viewLayoutGuide key="safeArea" id="zOb-OV-HXy"/>
</view> </view>
<navigationItem key="navigationItem" id="2kf-IY-WDY"/>
<simulatedToolbarMetrics key="simulatedBottomBarMetrics"/> <simulatedToolbarMetrics key="simulatedBottomBarMetrics"/>
<connections> <connections>
<outlet property="messageLabel" destination="6C9-Jb-ZZR" id="HeR-Qv-yfz"/> <outlet property="messageLabel" destination="6C9-Jb-ZZR" id="HeR-Qv-yfz"/>
@ -165,7 +185,7 @@
</viewController> </viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="rgH-br-nLG" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/> <placeholder placeholderIdentifier="IBFirstResponder" id="rgH-br-nLG" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects> </objects>
<point key="canvasLocation" x="1640.5797101449277" y="-23.4375"/> <point key="canvasLocation" x="874" y="-83"/>
</scene> </scene>
<!--Timeline--> <!--Timeline-->
<scene sceneID="fag-XH-avP"> <scene sceneID="fag-XH-avP">
@ -221,7 +241,7 @@
<toolbarItems/> <toolbarItems/>
<connections> <connections>
<segue destination="RMx-3f-FxP" kind="relationship" relationship="masterViewController" id="BlO-5A-QYV"/> <segue destination="RMx-3f-FxP" kind="relationship" relationship="masterViewController" id="BlO-5A-QYV"/>
<segue destination="vC3-pB-5Vb" kind="relationship" relationship="detailViewController" id="FRG-EO-hQw"/> <segue destination="mTc-f9-2dr" kind="relationship" relationship="detailViewController" id="3HU-Sb-w7Y"/>
</connections> </connections>
</splitViewController> </splitViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="cZU-Oi-B1e" sceneMemberID="firstResponder"/> <placeholder placeholderIdentifier="IBFirstResponder" id="cZU-Oi-B1e" sceneMemberID="firstResponder"/>
@ -283,17 +303,21 @@
<scene sceneID="r7l-gg-dq7"> <scene sceneID="r7l-gg-dq7">
<objects> <objects>
<placeholder placeholderIdentifier="IBFirstResponder" id="SLD-UC-DBI" userLabel="First Responder" sceneMemberID="firstResponder"/> <placeholder placeholderIdentifier="IBFirstResponder" id="SLD-UC-DBI" userLabel="First Responder" sceneMemberID="firstResponder"/>
<navigationController storyboardIdentifier="DetailNavigationViewController" useStoryboardIdentifierAsRestorationIdentifier="YES" toolbarHidden="NO" id="vC3-pB-5Vb" sceneMemberID="viewController"> <navigationController storyboardIdentifier="DetailNavigationController" useStoryboardIdentifierAsRestorationIdentifier="YES" toolbarHidden="NO" id="vC3-pB-5Vb" sceneMemberID="viewController">
<navigationBar key="navigationBar" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" id="DjV-YW-jjY"> <navigationBar key="navigationBar" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" id="DjV-YW-jjY">
<rect key="frame" x="0.0" y="44" width="414" height="44"/> <rect key="frame" x="0.0" y="44" width="414" height="44"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
</navigationBar> </navigationBar>
<toolbar key="toolbar" opaque="NO" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="Skn-vK-czG"> <toolbar key="toolbar" opaque="NO" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="Skn-vK-czG">
<rect key="frame" x="0.0" y="813" width="414" height="49"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
</toolbar> </toolbar>
<connections>
<segue destination="JEX-9P-axG" kind="relationship" relationship="rootViewController" id="yH5-Bf-My9"/>
</connections>
</navigationController> </navigationController>
</objects> </objects>
<point key="canvasLocation" x="154" y="-23"/> <point key="canvasLocation" x="1619" y="-83"/>
</scene> </scene>
</scenes> </scenes>
<resources> <resources>

View File

@ -11,7 +11,7 @@ import UIKit
class SystemMessageViewController: UIViewController { class SystemMessageViewController: UIViewController {
@IBOutlet weak var messageLabel: UILabel! @IBOutlet weak var messageLabel: UILabel!
var message: String? var message: String = NSLocalizedString("No Selection", comment: "No Selection")
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()

View File

@ -10,6 +10,13 @@ import UIKit
extension UISplitViewController { extension UISplitViewController {
static func template() -> UISplitViewController {
let splitViewController = UISplitViewController()
splitViewController.preferredDisplayMode = .allVisible
splitViewController.viewControllers = [UINavigationController()]
return splitViewController
}
func toggleMasterView() { func toggleMasterView() {
let barButtonItem = self.displayModeButtonItem let barButtonItem = self.displayModeButtonItem
if let action = barButtonItem.action { if let action = barButtonItem.action {