diff --git a/JSONCreator_iOS/JSONCreator/AppDelegate.swift b/JSONCreator_iOS/JSONCreator/AppDelegate.swift index 8e4892a..3ef7952 100644 --- a/JSONCreator_iOS/JSONCreator/AppDelegate.swift +++ b/JSONCreator_iOS/JSONCreator/AppDelegate.swift @@ -14,6 +14,7 @@ import VDS class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDelegate { var window: UIWindow? + var splitViewController: UISplitViewController? var mvcNav: UINavigationController? var dvcNav: UINavigationController? var mvc: UIViewController? @@ -28,19 +29,20 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. - let splitViewController = window!.rootViewController as! UISplitViewController - mvcNav = splitViewController.viewControllers[0] as? UINavigationController + splitViewController = window!.rootViewController as? UISplitViewController + NavigationHandler.shared().viewControllerToPresentOn = splitViewController + mvcNav = splitViewController?.viewControllers[0] as? UINavigationController mvcNav?.delegate = self mvc = mvcNav?.topViewController - dvcNav = splitViewController.viewControllers[splitViewController.viewControllers.count-1] as? UINavigationController + dvcNav = splitViewController?.viewControllers[splitViewController!.viewControllers.count-1] as? UINavigationController dvc = dvcNav?.topViewController - dvc?.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem + dvc?.navigationItem.leftBarButtonItem = splitViewController?.displayModeButtonItem dvc?.navigationItem.leftItemsSupplementBackButton = true - splitViewController.delegate = self - splitViewController.preferredDisplayMode = .allVisible + splitViewController?.delegate = self + splitViewController?.preferredDisplayMode = .allVisible let gr = UILongPressGestureRecognizer(target: self, action: #selector(jsonPasteAndGo)) - splitViewController.view.addGestureRecognizer(gr) + splitViewController?.view.addGestureRecognizer(gr) NotificationCenter.default.addObserver(forName: UIViewController.showDetailTargetDidChangeNotification, object: splitViewController, queue: nil) { [weak self] (notification) in if let strongSelf = self, let svc = notification.object as? UISplitViewController { diff --git a/JSONCreator_iOS/JSONCreator/DetailViewController.swift b/JSONCreator_iOS/JSONCreator/DetailViewController.swift index 38ca7b7..70a3143 100644 --- a/JSONCreator_iOS/JSONCreator/DetailViewController.swift +++ b/JSONCreator_iOS/JSONCreator/DetailViewController.swift @@ -20,9 +20,7 @@ class DetailViewController: UIViewController { return } - modalPresentationStyle = .formSheet - NavigationHandler.shared().viewControllerToPresentOn = self - + modalPresentationStyle = .fullScreen view.addSubview(textView) if UIDevice.current.userInterfaceIdiom == .pad { textView.font = UIFont.systemFont(ofSize: 40) @@ -78,7 +76,7 @@ class DetailViewController: UIViewController { let loadObject = MVMCoreLoadObject(pageJSON: page, modulesJSON: jsonObject.optionalDictionaryForKey(KeyModuleMap), requestParameters: nil, dataForPage: nil, delegateObject: nil), viewController.shouldFinishProcessingLoad(loadObject, error: &errorObject) { - Task(priority: .userInitiated) { + Task(priority: .userInitiated) { @MainActor in let gr = UILongPressGestureRecognizer(target: self, action: #selector(DetailViewController.close)) viewController.view.addGestureRecognizer(gr) @@ -86,7 +84,6 @@ class DetailViewController: UIViewController { CoreUIObject.sharedInstance()?.topNotificationHandler = NotificationHandler(with: topAlert) let split = MVMCoreUISplitViewController.setup(asMainController: nil, rightPanel: nil, topAlert: topAlert)! _ = split.view // Force loadView - //split.navigationController?.setViewControllers([viewController], animated: false) let done = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(self.close)) let spacer = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: self, action: nil) @@ -94,8 +91,8 @@ class DetailViewController: UIViewController { viewController.setToolbarItems([spacer, done], animated: false) split.navigationController?.setToolbarItems([spacer, done], animated: false) - NavigationHandler.shared().viewControllerToPresentOn = splitViewController - await NavigationHandler.shared().present(viewController: split) + NavigationHandler.shared().viewControllerToPresentOn = split + UIApplication.shared.delegate?.window??.rootViewController = split await NavigationHandler.shared().push(viewController: viewController, animated: false) } } else if let errorObject = errorObject { @@ -109,10 +106,9 @@ class DetailViewController: UIViewController { } @objc func close() { - guard let splitViewController = splitViewController else { return } - Task(priority: .userInitiated) { - await NavigationHandler.shared().navigate(with: .dismiss(viewController: splitViewController)) - } + guard let splitViewController = (UIApplication.shared.delegate as? AppDelegate)?.splitViewController else { return } + NavigationHandler.shared().viewControllerToPresentOn = splitViewController + UIApplication.shared.delegate?.window??.rootViewController = splitViewController } }