开发者

Modal UINavigationController with UIToolbar - Toolbar remains empty

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 UIBa开发者_运维问答rButtonItem[] { 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.


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜