带 UIToolbar 的 Modal UINavigationController - 工具栏保持为空
我试图将一个简单的 UIToolbar 放在模态呈现的 UINavigationController 的底部。在此示例中,它应包含两个按钮“取消”和“某事”。
...
UINavigationController modalNavigationController = new UINavigationController(someViewController);
modalNavigationController.NavigationBar.BarStyle = UIBarStyle.Black;
modalNavigationController.Toolbar.BarStyle = UIBarStyle.Black;
modalNavigationController.ToolbarHidden = false;
UIBarButtonItem cancelButton = new UIBarButtonItem("cancel", UIBarButtonItemStyle.Plain, delegate {
modalNavigationController.DismissModalViewControllerAnimated(true);
});
UIBarButtonItem flexSpace = new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace, null);
UIBarButtonItem someButton = new UIBarButtonItem("something", UIBarButtonItemStyle.Plain, delegate {
Console.WriteLine("here we are!");
});
modalNavigationController.ToolbarItems = new UIBarButtonItem[] { cancelButton, flexSpace, someButton };
parentController.PresentModalViewController(modalNavigationController, true);
...
工具栏出现并具有黑色样式(如指定的那样),但它不包含任何项目。我尝试在将隐藏设置为 false 之前分配项目,但没有效果。我还尝试使用 Toolbar.Items 和 Toolbar.Hidden 以及 SetToolbarItems() 和 SetToolbarHidden() 代替,但没有成功。
关于这里可能出什么问题的任何提示吗?谢谢
编辑:
网上的大多数示例都会创建自己的 UIToolbar 并将其添加为子视图。 UINavigationController 不需要这样做,对吧? AFAICT,它有一个内置的。
I'm trying to put a simple UIToolbar at the bottom of a modally presented UINavigationController. In this sample, it should contain two buttons "cancel" and "something".
...
UINavigationController modalNavigationController = new UINavigationController(someViewController);
modalNavigationController.NavigationBar.BarStyle = UIBarStyle.Black;
modalNavigationController.Toolbar.BarStyle = UIBarStyle.Black;
modalNavigationController.ToolbarHidden = false;
UIBarButtonItem cancelButton = new UIBarButtonItem("cancel", UIBarButtonItemStyle.Plain, delegate {
modalNavigationController.DismissModalViewControllerAnimated(true);
});
UIBarButtonItem flexSpace = new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace, null);
UIBarButtonItem someButton = new UIBarButtonItem("something", UIBarButtonItemStyle.Plain, delegate {
Console.WriteLine("here we are!");
});
modalNavigationController.ToolbarItems = new UIBarButtonItem[] { cancelButton, flexSpace, someButton };
parentController.PresentModalViewController(modalNavigationController, true);
...
The toolbar appears and has black style (as assigned), it does not contain any items though. I've tried assigning the items before setting hidden to false, no effect. I also tried using Toolbar.Items and Toolbar.Hidden as well as SetToolbarItems() and SetToolbarHidden() instead, with no luck.
Any hints on what might be wrong here? Thanks
EDIT:
Most samples on the net create their own UIToolbar and add it as a subview. That is not required with a UINavigationController, right? AFAICT, it has one built-in.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没关系,我不知何故错过了工具栏项目必须在每个子视图的基础上提供。
这有效:
Nevermind, I somehow missed that toolbar items have to be supplied on a per-subview basis.
This works: