When MyView gets pushed on to the NavigationController, I have the following code
public override void ViewDidLoad ()
{
this.NavigationController.Toolbar.SetItems(new UIBarButtonItem[] {
new UIBarButtonItem("Next",UIBarButtonItemStyle.Plain, ClickNext)
}, true);
this.NavigationItem.Title = "Proposal Plan - Step 1";
}
The Title gets set properly, and the code runs but in my Toolbar at the bottom of the view I don't have the "Next" button I am expecting. I put a breakpoint and verified that the Toolbar after running that line does have my button, but still nothing.
What am I开发者_如何学JAVA missing? [ EDIT @ 2:05pm EDT ] I'm trying to add buttons to the bottom toolbar, for my example I happen to have called it next, leading to confusion.
To add items to your navigation controller you should always access the objects from the context of the view the code is executed.
You should use the NavigationItem in the current view to add a buttons to the navigation bar:
public override void ViewDidLoad ()
{
this.NavigationItem.Title = "Proposal Plan - Step 1";
this.NavigationItem.RightBarButtonItem = new UIBarButtonItem("Next", UIBarButtonItemStyle.Plain, ClickNext);
}
The same goes for the toolbar at the bottom of you navigation controller. You should use the ToolBarItems in the current view
this.ToolbarItems = new UIBarButtonItem[] {
new UIBarButtonItem("Next",UIBarButtonItemStyle.Plain, ClickNext)
};
精彩评论