Question

I'm new to Xamarin IOS and I have a project which needs this flyout navigation.

var navigation = new FlyoutNavigationController {
                    // Create the navigation menu
                    NavigationRoot = new RootElement ("Navigation") {
                        new Section ("Menu") {
                            new StringElement ("Recipe"),
                            new StringElement ("Recipe Basket"),
                            new StringElement ("Meal Planner"),
                            new StringElement ("Grocery List"),
                            new StringElement ("Social"),
                            new StringElement ("Videos"),
                            new StringElement ("News Feed"),
                            new StringElement ("Partners"),
                        }
                    },
                    // Supply view controllers corresponding to menu items:

                    ViewControllers = new [] {
                        new UIViewController { View = new UILabel { Text = "Animals (drag right)" } },
                        new UIViewController { View = new UILabel { Text = "Vegetables (drag right)" } },
                        new UIViewController { View = new UILabel { Text = "Minerals (drag right)" } },


                    },
                }; 

This code just presents the UILabel. How can I do this to send it to a specific view controller?

Please help.

Thanks in advance.

No correct solution

OTHER TIPS

Do what vinaykumar said, but you also want to open the FlyoutNavigationController from those UIViewControllers, so you have to pass that initial one you created to those controllers.

Otherwise if you just open your view controller, you won't be able to get the menu again.

I'm opening navigation controllers like so:

MainViewController in ViewDidLoad:

        UIStoryboard board = UIStoryboard.FromName("MainStoryboard_iPhone", null);

        UINavigationController nav = (UINavigationController)board.InstantiateViewController("nav");
        SearchViewController searchVC = (SearchViewController)nav.ViewControllers[0];

         // Passing flyoutnavigation here
        searchVC.navigation = navigation;

        SettingsViewController settingsVC = (SettingsViewController)board.InstantiateViewController("settings");
        UINavigationController navSettings = new UINavigationController(settingsVC);

        // Passing flyoutnavigation here
        settingsVC.navigation = navigation;

        navigation.ViewControllers = new[]
        {
            nav,
            navSettings
        };

In the other view controllers, (Settings and Search in my example), I have a public variable to store the FlyoutNavigationController (set in MainViewController) then add a button to open the FlyoutNavigationController that was passed:

    // Set in MainViewController
    public FlyoutNavigationController navigation;

    public override void ViewDidLoad()
    {

        base.ViewDidLoad();

        // Add button to allow opening the FlyoutNavigationController
        NavigationItem.LeftBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Action, delegate
        {
            navigation.ToggleMenu();
        });
    }

you have to add the FlyoutNavigationController's View to your View

// Show the navigation view
navigation.ToggleMenu ();
View.AddSubview (navigation.View);

This code just presents the UILabel.

because you are only providing UILable as a view to your new UIViewController.

View = new UILabel { Text = "Animals (drag right)" }

How can I do this to send it to a specific view controller?

Provide your UIViewController instead of new UIViewController

for instance change the following code

ViewControllers = new [] {
                        new UIViewController { View = new UILabel { Text = "Animals (drag right)" } },
                        new UIViewController { View = new UILabel { Text = "Vegetables (drag right)" } },
                        new UIViewController { View = new UILabel { Text = "Minerals (drag right)" } },

                },

to

ViewControllers = new [] {
                            new <your_UIViewController>(),
                            new <your_UIViewController>(),
                            new <your_UIViewController>(),

                    },

Hope this helps you, let me know if you faced any issue while implementing the same.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top