How to call different Storyboards via Swift for iOS?

前端 未结 1 1955
清歌不尽
清歌不尽 2020-12-16 05:47

I created an app with three different Storyboards for each iOS device family. Now I don\'t know how to choose the right Storyboard when the app starts? I am checking the scr

相关标签:
1条回答
  • 2020-12-16 06:27

    I guess you want to open a view? If so this code will do the job:

    var mainView: UIStoryboard!
    mainView = UIStoryboard(name: "vcLogin", bundle: nil)
    let viewcontroller : UIViewController = mainView.instantiateViewControllerWithIdentifier("iPhone5") as UIViewController
    self.window!.rootViewController = viewcontroller
    

    It will open the view controller with id: yourViewControllerId

    You need to give your viewcontroller an identifier. You do that by highlighting your view controller and then give it a identifier: You then put your identifier in StoryBoard ID. enter image description here

    So for you it will be:

    if screenHeight == 480 {
      deviceFamily = "iPhoneOriginal"
      // Load Storyboard with name: iPhone4
      var mainView: UIStoryboard!
      mainView = UIStoryboard(name: "vcLogin", bundle: nil)
      let viewcontroller : UIViewController = mainView.instantiateViewControllerWithIdentifier("iPhone4") as UIViewController
      self.window!.rootViewController = viewcontroller
    }
    
    0 讨论(0)
提交回复
热议问题