使用 MonoDevelop,我一直在研究使用 FlyoutNavigationController 实现侧面滑出菜单的 IOS,但遇到了一些障碍。
首先,如何访问elements
字体生成的 list
?
我可以轻松修改行高等,但不确定如何继续修改 list
项目,这可以用 tablesource
来删除吗?和项目styling
?
其次,如何从此列表中打开 View ? 目前默认使用空 View ,但要从侧面菜单列表打开新 View ,我尝试使用推送导航 Controller ,但无法打开。
欢迎任何想法。
navigation = new FlyoutNavigationController();
navigation.View.Frame = UIScreen.MainScreen.Bounds;
View.AddSubview(navigation.View);
navigation.NavigationRoot = new RootElement ("Menu List")
{
new Section ("Menu List")
{
from page in SlideList
select new StringElement (page.title) as Element
}
};
navigation.NavigationTableView.BackgroundColor = UIColor.DarkGray;
navigation.NavigationTableView.RowHeight = 30;
navigation.NavigationTableView.SeparatorStyle = UITableViewCellSeparatorStyle.SingleLine;
navigation.NavigationTableView.SeparatorColor = UIColor.LightGray;
navigation.NavigationTableView.SectionHeaderHeight = 60;
//navigation.NavigationTableView.DataSource = SlideList;
//navigation.ViewControllers = Array.ConvertAll (MenuItems, title => new UINavigationController (new TaskPageController (navigation, title)));
navigation.ViewControllers = Array.ConvertAll (MenuItems, title => new TaskPageController (navigation, title));
this.NavigationItem.LeftBarButtonItem = new UIBarButtonItem (UIBarButtonSystemItem.Action, delegate {
navigation.ToggleMenu();
});
最佳答案
我以前没有使用过 FlyOutNavigationController,但我看了一下这个例子: https://github.com/xamarin/FlyOutNavigation
看起来您应该拥有与 Controller 相同数量的 StringElements。对于 ViewControllers 数组,您似乎可以提供自己的自定义 Controller ,而不仅仅是普通的 ViewController。之后,单击列表项应自动导航到适当的 Controller 。
关于样式,查看此 NavigationController 的源代码,我没有看到太多能够对单元格进行样式化的内容。我快速搜索了如何设计 MonoTouch 对话框列表的样式,看起来没有一个简单的方法而不使用子类化元素:
Monotouch Dialog: Styling Elements
但是,我可以与您分享我如何在没有 Dialog 框架的情况下完成您提出的两个问题。
您可以创建一个扩展 UITableViewSource 的自定义类: http://docs.xamarin.com/guides/ios/user_interface/tables/part_2_-_populating_a_table_with_data
在 GetCell 方法重写中,您可以获取单元格标签的实例并设置字体,如下所示:
cell.TextLabel.Font = UIFont.FromName("TitlingGothicFB Cond", 20);
您可以使用自定义 UITableViewSource 类做的另一件事是创建自定义事件:
public event EventHandler ListItemSelected;
在 RowSelected 方法中,您可以调度此事件:
public override void RowSelected (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
{
ListItemSelected(this, new MyCustomEventArgs(indexPath.Row));
}
在负责实例化此 TableSource 的 Controller 类中,您可以像这样监听和处理此事件:
var customTableSource = new CustomTableSource(myList);
MyTable.Source = customTableSource;
customTableSource.ListItemSelected += (object sender, EventArgs e) => {
if((e as MyCustomEventArgs).rowSelected == 1){
this.NavigationController.PushViewController(new MyNextViewController(), true));
}
}
关于c# - 弹出导航 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16484823/