Is there anyone who can help me to explain how to make UISpliterController programmatically in Swift. In my application I want to apply the supporting feature of iphone device and ipad. If the app is running on iphone then use single controler but if the application is running on ipad then use UISpliterController with existing ViewController.
I have tried it but it always produce blackscreen Here is my code.
if UIDevice.current.userInterfaceIdiom == .pad {
let spliterVC = UISplitViewController()
let homeNavControler = mainStoryboard.instantiateViewController(withIdentifier: "homeViewController") as! HomeViewController
let secondVC = mainStoryboard.instantiateViewController(withIdentifier: "secondViewController") as! SecondViewController
spliterVC.viewControllers = [homeNavControler,secondVC]
appdelegate.window?.rootViewController = spliterVC
}
if you want do it with navigationController, then try it:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
if UIDevice.current.userInterfaceIdiom == .pad {
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
self.window!.backgroundColor = UIColor.whiteColor()
var splitViewController = UISplitViewController()
var homeViewController = HomeViewController()
var secondViewController = SecondViewController()
var homeNavigationController = UINavigationController(rootViewController:homeViewController)
var secondNavigationController = UINavigationController(rootViewController:secondViewController)
splitViewController.viewControllers = [homeNavigationController,secondNavigationController]
self.window!.rootViewController = splitViewController
self.window!.makeKeyAndVisible()
return true
} else {
// use single controller for iPhone and return that controller
}
}
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