I'm making an app where I have a key/value in NSUserDefaults which allows the app on start up to detect if this is the first time the app is turned on on the device. If it's the first time, I want the splitVC(which is also the rootVC)'s detail View to be my pageViewController(tutorial), else I want it to go straight into the app (another view controller, lets call it todayViewController).
I currently have a class for my SplitVC (GlobalSplitViewController.swift), but I currently have no idea how to programmatically change the detail view in ViewDidLoad.
Also, in storyboard, my splitVC's detail segue is connected to todayViewController and it's master segue to a menuVC, which is working perfectly.
Thanks in advance!
Code in GlobalSplitViewController.swift:
import UIKit
class GlobalSplitViewController: UISplitViewController, UISplitViewControllerDelegate {
var firstTime: Bool!
override func viewDidLoad() {
super.viewDidLoad()
self.delegate = self
firstTime = loadFistTime()
if firstTime == true {
//load tutorials pageVC
} else {
//load todayVC
}
}
func splitViewController(svc: UISplitViewController, shouldHideViewController vc: UIViewController, inOrientation orientation: UIInterfaceOrientation) -> Bool {
return true
}
Starting with iOS 8 you can use:
splitViewController?.showDetailViewController(vc, sender: self)
or if you want to replace primary controller
splitViewController?.show(vc, sender: self)
In AppDelegate for example you can check your UserDefaults, and with Switch or If/else you can change the splitView. Here is an example of changing the detailViewController.
let detailViewController = self.storyboard?.instantiateViewControllerWithIdentifier("DetailNavigationViewController") as! UINavigationController
self.splitViewController?.viewControllers[1] = detailViewController
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With