I’ve a UISplitViewController with two UINavigationControllers as main and element view controllers, created utilizing Storyboard. The first has a static UITableViewController and clicking on a row would set the element view to load within the element view navigation controller.
Every thing is working as anticipated, besides once I set overrideUserInterfaceStyle to “darkish mode”. When that’s accomplished, the UISplitViewController’s viewControllers array has only one aspect in it – the first view controller.
I attempted to recreate the issue utilizing a simplified instance, and succeeded in reproducing the difficulty.
The reproducible take a look at case is at https://github.com/sridharrajagopal/TestApp
protocol RootSettingsViewControllerSelectionDelegate : AnyObject {
func viewControllerSelected(_ vc: String)
}
class RootSettingsViewController: UITableViewController, MFMailComposeViewControllerDelegate {
weak var delegate: RootSettingsViewControllerSelectionDelegate?
override func viewDidLoad() {
tremendous.viewDidLoad()
if (UIDevice.present.userInterfaceIdiom == .pad) {
let indexPath = IndexPath(row: 0, part: 0)
tableView.selectRow(at: indexPath, animated: true, scrollPosition: UITableView.ScrollPosition.prime)
tableView.delegate?.tableView!(tableView, didSelectRowAt: indexPath)
}
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if (indexPath.part == 2 && indexPath.row == 2) {
// emailUs()
} else if (indexPath.part == 0 && indexPath.row == 0) {
delegate?.viewControllerSelected("A")
} else if (indexPath.part == 0 && indexPath.row == 1) {
delegate?.viewControllerSelected("B")
} else if (indexPath.part == 0 && indexPath.row == 2) {
delegate?.viewControllerSelected("C")
}
if let detailViewController = delegate as? SettingsSecondaryNavigationViewController {
splitViewController?.showDetailViewController(detailViewController, sender: nil)
}
}
}
class SettingsSecondaryNavigationViewController: UINavigationController {
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
tremendous.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
}
required init?(coder aDecoder: NSCoder) {
tremendous.init(coder: aDecoder)
}
override func viewDidLoad() {
tremendous.viewDidLoad()
}
}
extension SettingsSecondaryNavigationViewController: RootSettingsViewControllerSelectionDelegate {
func viewControllerSelected(_ vc: String) {
if (vc == "A") {
let detailViewController = UIViewController()
detailViewController.view.backgroundColor = .crimson
self.viewControllers = [detailViewController]
} else if (vc == "B") {
let detailViewController = UIViewController()
detailViewController.view.backgroundColor = .inexperienced
self.viewControllers = [detailViewController]
} else if (vc == "C") {
let detailViewController = UIViewController()
detailViewController.view.backgroundColor = .blue
self.viewControllers = [detailViewController]
} else if (vc == "D") {
let detailViewController = UIViewController()
detailViewController.view.backgroundColor = .purple
self.viewControllers = [detailViewController]
}
}
}
class SettingsSplitViewController: UISplitViewController, UISplitViewControllerDelegate {
override func viewDidLoad() {
tremendous.viewDidLoad()
delegate = self
let detailViewController =
(self.viewControllers.final as? SettingsSecondaryNavigationViewController)
let primaryViewController =
(self.viewControllers.first as? UINavigationController)?
.topViewController as? RootSettingsViewController
// That is the place it bombs, as detailViewController is nil
primaryViewController!.delegate = detailViewController!
preferredDisplayMode = UISplitViewController.DisplayMode.oneBesideSecondary
}
func splitViewController(
_ splitViewController: UISplitViewController,
collapseSecondary secondaryViewController: UIViewController,
onto primaryViewController: UIViewController
) -> Bool {
return true
}
}
I’m fairly stumped right now. If overrideUserInterfaceStyle is .gentle or .unspecified (match system settings), every thing’s working high-quality.
I see that when loading the app, the SettingsSecondaryNavigationViewController’s viewDidLoad will get referred to as when overrideUserInterfaceStyle is .gentle or .unspecified (even earlier than loading the precise UISplitViewController, however would not get referred to as when .darkish mode.
My first query is that if what I am doing is okay, or has some inherent issues that is manifesting because the “darkish mode” problem.
Any insights or pointers can be tremendously appreciated!