我是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。如何将其发送到特定的视图控制器?
请帮忙。
提前致谢。
答案 0 :(得分:1)
做vinaykumar所说的,但你也想从那些UIViewControllers中打开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();
});
}
答案 1 :(得分:0)
您必须将FlyoutNavigationController's View
添加到View
// Show the navigation view
navigation.ToggleMenu ();
View.AddSubview (navigation.View);
答案 2 :(得分:0)
此代码仅显示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 [] {
new <your_UIViewController>(),
new <your_UIViewController>(),
new <your_UIViewController>(),
},
希望这对您有所帮助,如果您在实施同样的问题时遇到任何问题,请告诉我。