Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/94.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在xamarin IOS中使用弹出式导航_Ios_Iphone_Xamarin.ios_Xamarin - Fatal编程技术网

如何在xamarin IOS中使用弹出式导航

如何在xamarin IOS中使用弹出式导航,ios,iphone,xamarin.ios,xamarin,Ios,Iphone,Xamarin.ios,Xamarin,我是Xamarin IOS的新手,我有一个项目需要这个弹出式导航 var navigation = new FlyoutNavigationController { // Create the navigation menu NavigationRoot = new RootElement ("Navigation") { new Section ("Menu") {

我是Xamarin IOS的新手,我有一个项目需要这个弹出式导航

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)" } },


                    },
                }; 
这段代码只是显示UILabel。如何将其发送到特定的视图控制器

请帮忙


提前感谢。

您必须将
弹出式导航控制器的视图添加到
视图中

// Show the navigation view
navigation.ToggleMenu ();
View.AddSubview (navigation.View);
这段代码只是显示UILabel

因为您只将UILable作为视图提供给新的UIViewController

View = new UILabel { Text = "Animals (drag right)" }
如何将其发送到特定的视图控制器

提供您的UIViewController,而不是新的UIViewController

例如,更改以下代码

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)" } },

                },

ViewControllers=new[]{
新的(),
新的(),
新的(),
},

希望这对您有所帮助,如果您在实现相同功能时遇到任何问题,请告诉我。

按照vinaykumar所说的做,但您也希望从这些UIViewController打开FlyoutNavigationController,因此您必须将创建的初始控件传递给这些控制器

否则,如果只打开视图控制器,将无法再次获取菜单

我正在打开导航控制器,如下所示:

ViewDidLoad中的MainViewController:

        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
        };
在其他视图控制器(在我的示例中为设置和搜索)中,我有一个公共变量来存储FlyoutNavigationController(在MainViewController中设置),然后添加一个按钮以打开传递的FlyoutNavigationController:

    // 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();
        });
    }

你能分享一下你最终输出的屏幕截图吗。比如它在你的iPhone上的表现。我希望左侧导航按钮项显示为4个水平条,但没有得到它。那么你能发布你的屏幕截图吗?谢谢!,我希望我能分享截图,但由于某些原因,我无法分享。弹出式导航的工作原理与幻灯片菜单类似。左侧导航栏按钮只是“NavigationItem.LeftBarButtonim”
    // 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();
        });
    }