gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 12:52:14 25 4
gpt4 key购买 nike

我是 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。我怎样才能将它发送到特定的 View Controller ?

请帮忙。

提前致谢。

最佳答案

按照 vinaykumar 所说的进行操作,但您还想从那些 UIViewController 中打开 FlyoutNavigationController,因此您必须将您创建的初始 Controller 传递给这些 Controller 。

否则如果你只是打开你的 View Controller ,你将无法再次获得菜单。

我像这样打开导航 Controller :

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
};

在其他 View Controller 中(在我的示例中为设置和搜索),我有一个公共(public)变量来存储 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();
});
}

关于ios - 如何在 xamarin IOS 中使用弹出导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22161432/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com