Baseflow / Xamarin-Sidebar

A slideout navigation control for Xamarin.iOS
https://baseflow.com
Apache License 2.0
113 stars 67 forks source link

Can I use it with UINavigationController in Storyboard? #20

Closed xplatsolutions closed 9 years ago

xplatsolutions commented 9 years ago

I'm trying to use the Sidebar with having all my controllers setup in the Storyboard, but it hangs forever if I have my initial UINavigationController with the RootController inside the Storyboard.

Taking the UINavigationController out and creating with code it will work but this gives me pain with using the MvvmLight NavigationService which is initialized with the UINavigationController initially from the Storyboard.

Problem is when creating the Sidebar.

appD.SideBarController = new SidebarController(this, appD.NavController, leftSideMenuController);

I set the navigation controller at the FinishedLaunching method in the AppDelegate.

Any thoughts?

jdehlin commented 9 years ago

The information in the issue linked below might help.

https://github.com/jdehlin/Xamarin-Sidebar/issues/11

xplatsolutions commented 9 years ago

That is all good and understandable but I don't read somewhere how or if it is possible to use the initial UINavigationController that I have in my storyboard and not creating it in code.

In a nutshell what I want my code to be is.

AppDelegate:

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            NavController = (UINavigationController)Window.RootViewController;
            return true;
        }

RootViewController which is the Root controller of the UINavigationController in the Storyboard:

partial class RootViewController : UIViewController
    {
        public RootViewController (IntPtr handle) : base (handle)
        {
        }

        public override void ViewDidLoad ()
        {
            base.ViewDidLoad ();

            //Set Navigation controller reference so we can use it everywhere
            AppDelegate appD = UIApplication.SharedApplication.Delegate as AppDelegate;

            MainViewController schedulerController = (MainViewController)Storyboard.InstantiateViewController("MainViewController");
            SideMenuViewController leftSideMenuController = (SideMenuViewController)Storyboard.InstantiateViewController("SideMenuViewController");
            appD.NavController.PushViewController(schedulerController,false);
            appD.SideBarController = new SidebarController(this, appD.NavController, leftSideMenuController);
            appD.SideBarController.MenuWidth = 250;
            appD.SideBarController.ReopenOnRotate = false;
            appD.SideBarController.MenuLocation = SidebarController.MenuLocations.Left;
        }
    }

I don't do anything differently than what you show in a Storyboard sample I found on an issue while searchin, but embedding the RootViewController in a UINavigationController on the Storyboard.

The above code results in preventing the app to start which smells like circular code somewhere in this line of code:

appD.SideBarController = new SidebarController(this, appD.NavController, leftSideMenuController);

Thanks.

pilouk commented 9 years ago

Please create a new nav controller from code behind. Don't use the storyboard nav controller because it will result with some error when your trying to segue other view..,

Always use the nav controller newly created for pushing view and hold a reference in App delegate.

Maybe u miss this line in the root view controller ( the new instance is important here ):

appD.GETSET_NavController = new UINavigationController();

Sorry for being a little late here...