iOS MonoTouch: Show / Hide the Toolbars or Individual Toolbar Buttons

When you are navigating across screens in your application, you trigger “ViewWillAppear”. This function is helpful when you need something to happen every time you view the screen.

public override void ViewWillAppear (bool animated){
	base.ViewWillAppear (animated);
	this.NavigationController.SetNavigationBarHidden (true, animated); //-- hide the navigation bar
	this.NavigationController.SetToolbarHidden(false,animated); //-- show the bottom toolbar
	if (someCondition == null) {
		//-- show these buttons in the toolbar
		this.SetToolbarItems( new UIBarButtonItem[] {
			spacer,createButton,spacer,helpButton,spacer
		} , false);
	} else {
		//-- show these buttons in the toolbar otherwise
		this.SetToolbarItems( new UIBarButtonItem[] {
			spacer,loginButton,spacer,passwordButton,spacer,helpButton,spacer
		} , false);
	}
}

Leave a comment