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.
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 };
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With