Segue from one storyboard to a different storyboard?

前端 未结 9 1896
孤独总比滥情好
孤独总比滥情好 2020-12-13 18:43

I have too many views on one storyboard which is causing it to run really slow. I have been told that a solution to this issue would be to split the one storyboard into mult

相关标签:
9条回答
  • 2020-12-13 19:19

    First of all, breaking up a storyboard into multiple separate ones is a great idea, saves a lot of headache (especially if you are on a team and dealing with lots of merge conflicts in the storyboard file).

    Now to answer your question - you cannot perform a segue between two storyboards necessarily, but one solution I've had great success with is to do something like this:

    - (IBAction)buttonPressed:(id)sender {
    
        UIViewController *otherVC = [[UIStoryboard storyboardWithName:@"SecondStoryboard" bundle:nil] instantiateInitialViewController]; //Or get a VC by its identifier
    
        [self.navigationController pushViewController:otherVC animated:YES];
    }
    

    Just load up the other storyboard and either call instantiateInitialViewController or instantiateViewControllerWithIdentifier: then do whatever transition you would like.

    Hope this helps.

    0 讨论(0)
  • 2020-12-13 19:22

    In Swift (iOS 8.1) this is pretty easy:

      var storyboard: UIStoryboard = UIStoryboard(name: "Another", bundle: nil)
      var vc = storyboard.instantiateViewControllerWithIdentifier("NextViewController") as AnotherViewController
      self.showViewController(vc, sender: self)
    

    Update for Swift 3:

    let storyboard: UIStoryboard = UIStoryboard(name: "Another", bundle: nil)
    let vc = storyboard.instantiateViewController(withIdentifier: "NextViewController") as! AnotherViewController
    self.show(vc, sender: self)
    
    0 讨论(0)
  • 2020-12-13 19:22

    Swift 3

    let vc = UIStoryboard(name: "StoryboardName", bundle: nil).instantiateViewController(withIdentifier: "ViewControllerIdentifier") as? ExpectedViewControllerClass
    self.show(vc, sender: self)
    

    Where the "StroboardName" is the name of your .storyboardfile. The "ViewControllerIdentifier" is the id of the View in the story board. And "self" is any UIViewController

    In my case, the identifier was "chooseCountryViewController"

    0 讨论(0)
提交回复
热议问题