Home Features Docs Blog Support GitHub

Move between Activities/Storyboards with Multi-OS

Hey everyone, I know how to switch between activities for Android UIs using the Intent library. Now I want to know how I can do this with IOS storyboards with Multi-OS in Android Studio. I have my main storyboard with a button to go to my second storyboard and a button in my second storyboard to go to my first storyboard. How do I implement this functionality? Thanks.

You’ve actually got couple of ways switching screens / view controllers. It also heavily depends on the complexity of your app, since for an app with less screens it might be better to have one main storyboard with some few view controllers in it. Splitting it up into several storyboards is good, once the complexity is increasing.

You can either:

  • Use one main storyboard and load your view controllers from the main bundle:
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let vc = storyboard.instantiateViewController(withIdentifier: "viewController")
    self.navigationController!.pushViewController(vc, animated: true)
    
  • Use several storyboards and load your view controllers:
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MyStoryboardName" bundle:nil];
    UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"myViewController"];
    vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentViewController:vc animated:YES completion:NULL];
    
    https://stackoverflow.com/a/9896940/1019562
  • Use layout interface builder (*.xib) files to load and present view controllers directly:
    let myVC = NSBundle.mainBundle().loadNibNamed("MyViewController", owner: self, options: nil)[0] as? MyViewController
    
    https://stackoverflow.com/a/37047793/1019562

Good thing about Multi OS Engine is, that it can be translated from Swift quite easily, so you’ll get following solutions from above:

  • Loading from main / other storyboard:

    UIStoryboard storyboard = UIStoryboard.storyboardWithNameBundle("MyStoryboardName", null);
    MyViewControllerClass controller = MyViewControllerClass.class.cast(storyboard.instantiateViewControllerWithIdentifier("StoryboardId"));
    
  • Loading from xib file:

    UINib nib = UINib.nibWithNibNameBundle("MyXibFilenameWithoutExtension", NSBundle.mainBundle());
    MyViewControllerClass controller = (MyViewControllerClass) nib.instantiateWithOwnerOptions(nsOwner, null).get(0);
    

    Important is here, that you must not forget to set the file owner of the XIB as described on Stackoverflow!

Hope that helps :slight_smile: