带 UIToolbar 的 Modal UINavigationController - 工具栏保持为空

发布于 2024-10-15 02:39:52 字数 1302 浏览 5 评论 0原文

我试图将一个简单的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

江南烟雨〆相思醉 2024-10-22 02:39:52

没关系,我不知何故错过了工具栏项目必须在每个子视图的基础上提供。

这有效:

someViewController.ToolbarItems = new UIBarButtonItem[] { cancelButton, flexSpace, someButton };

Nevermind, I somehow missed that toolbar items have to be supplied on a per-subview basis.

This works:

someViewController.ToolbarItems = new UIBarButtonItem[] { cancelButton, flexSpace, someButton };
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文