I have two separate storyboards for iPad and iPhone, they have the same classes, outlets and etc, but different layouts.
I found that I can detect device type on app launch with UIScreen.main.traitCollection.userInterfaceIdiom
, but now I need to call correct storyboard. How do I do that? Am I even on the right direction? All I found related to this problem is like posts made 8-9 years ago so I don’t even understand syntax sometimes.
Thanks in advance!
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let iPhoneStoryboard = UIStoryboard(name: "IPhone", bundle: nil)
let iPadStoryboard = UIStoryboard(name: "IPad", bundle: nil)
let type = UIScreen.main.traitCollection.userInterfaceIdiom
switch type {
case .phone:
// need to call something here
case .pad:
// need to call something here
@unknown default:
fatalError()
}
2
Answers
You have to instantiate the view controller by
instantiateInitialViewController()
orinstantiateViewController(withIdentifier:)
HII can you try to set instantiateViewController to UINavigationController and set identifier like as "Ipad" or "Iphone" and set first controller of storyboard to rootviewcontroller of UINavigationController and set initial viewcontrolled to UINavigationController like as…