How to trigger LaunchScreen storyboard from Login(authentication storyboard)

wenjunfan.9218wenjunfan.9218 USMember
edited January 2017 in Xamarin.iOS

Hi, I now have two storyboard one for login/register, and the other one for the launching home page.

The second one I had a side navigation bar(follow the step from Xamarin component, so the LaunchScreen has it's own rootviewcontroller).

Then from the AppDelegate.cs : I had following:

public LaunchViewController RootViewController { get { return Window.RootViewController as LaunchViewController; } }

 public override bool LaunchViewController(UIApplication application, NSDictionary launchOptions)
        {
 Window = new UIWindow(UIScreen.MainScreen.Bounds);
            // set our root view controller with the sidebar menu as the apps root view controller
            Window.LaunchViewController= new LaunchViewController();
            Window.MakeKeyAndVisible();
            return true;
}

then I add a storyboard reference to my Main.Storyboard, which had Navigation and root my first viewController as LoginViewController, add a segue to show my LauchViewController from Second Storyboard.

Now is I run them together, only the launchviewController works, and the first login page is missing.

Could anyone help with that?
Or please suggest a better login->sidebarnavigation logic.
Thanks!

BTW, I am using the visual studio 2015 for this ios application

Answers

  • @JohnMiller Thanks for your help in advance:)

  • JohnMillerJohnMiller USForum Administrator, Xamarin Team Xamurai

    @wenjunfan.9218,

    I believe you will have to do something conditional in your FinishedLaunching method.

    For example, you might want to only show the login for certain flows:

    // In the FinishedLaunching method
    if(shouldLoginFirst)
    {
        storyboard = UIStoryboard.FromName ("LoginStoryboard", null);
        startController = storyboard.InstantiateInitialViewController () as LoginController;
    }
    else
    {
        storyboard = UIStoryboard.FromName ("MainStoryboard", null);
        startController = storyboard.InstantiateInitialViewController () as LoginController;
    }
    
    window.RootViewController = startController;
    window.MakeKeyAndVisible ();
    
  • @JohnMiller Thanks for your reply, I have something like

    // provide access to the sidebar controller to all inheriting controllers
    protected SidebarNavigation.SidebarController SidebarController {
    get {
    return (UIApplication.SharedApplication.Delegate as AppDelegate).RootViewController.SidebarController;
    }
    }

    .....
    public override void ViewDidLoad()
    {
    base.ViewDidLoad();
    NavigationItem.SetLeftBarButtonItem(
    new UIBarButtonItem(UIImage.FromBundle("action_menu")
    , UIBarButtonItemStyle.Plain
    , (sender, args) => {
    SidebarController.ToggleMenu();
    }), true);
    }
    on my BaseController, and this one borrow form Delegate to set a sidebar navigation, if I do not define the Rootview from my launchviewcontroller, then this side bar function missing, for example, if I command below lines from AppDelegate.cs
    Window = new UIWindow(UIScreen.MainScreen.Bounds);
    // set our root view controller with the sidebar menu as the apps root view controller
    Window.LaunchViewController= new LaunchViewController();
    Window.MakeKeyAndVisible();

    Only the Login works, not the LaunchViewController, I now combined the two storyboard together, and hope to use segue to connect from loginButton with LaunchViewController, any suggestion? My logic now is like AppDelegate->LaunchViewController(blank uiviewcontroller in storyboard)->BaseController(no storyboard)-> function in MenuViewController(as sidebar navigation) and the HomeViewController(as the first page after login). then I have storyboard with navigation and root segue for LoginViewController.

    Please let me know if I can be more clear.

    Thanks a lot!

  • Michael_ShapiroMichael_Shapiro USMember ✭✭✭

    @JohnMiller - I like your approach with two storyboards. Do you know if it can coexist with MVVM Light navigation pattern?

  • JohnMillerJohnMiller USForum Administrator, Xamarin Team Xamurai

    @Michael_Shapiro,

    I am not familiar with MVVM Light. What trouble are you having adapting this?

  • Michael_ShapiroMichael_Shapiro USMember ✭✭✭

    @JohnMiller - I checked and ti won't work. MVVM Light is basically a "black box" navigation framework (among other things). At the start of the app, in FinishedLaunching, I must associate this navigator with the root view controller
    nav.Initialize((UINavigationController)Window.RootViewController);

    Basically all navigation is done by MVVM Light are now directed to one Navigation COntroller that is, let's say, belongs to storyboard#1. I would not be able to navigate to a different storyboard without first associating the mvvm navigator with a different storyboard/navigator controller.

    I really cannot ditch the mvvm light becasue I already have Android app and PCL project based on mvvm light framework. iOS app just needs to use the same infrastructure at this point.

    I'll post a more broad question in a separate post. I simply want to understand what is the best approach of starting with a Login screen and moving forward to the other app functional areas (after successful login) and preventing users from navigating BACK to the login screen which is irrelevant at that point. I know it is a very common question - however I was not able to find answer that works the best with MVVM Light. I like your approach though.

  • KratiChauhanKratiChauhan USMember ✭✭

    @Michael_Shapiro : We are also in the same situation where we want to navigate between storyboards. Did you find a solution to your problem? If yes, can you please share.

  • Michael_ShapiroMichael_Shapiro USMember ✭✭✭

    @KratiChauhan - I decided t o simplify the design and stick with just one story board.

Sign In or Register to comment.