MonoTouch.UIKit.UINavigationBar Class
A MonoTouch.UIKit.UIView that displays the standard hierarchical navigation metaphor for iOS.

See Also: UINavigationBar Members

Syntax

[MonoTouch.Foundation.Register("UINavigationBar", true)]
public class UINavigationBar : UIView, IUIBarPositioning, IDisposable

See Also

UINavigationItem
UINavigationController
UIBarButtonItem

Remarks

The MonoTouch API supports two styles of event notification: the Objective-C style that uses a delegate class or the C# style using event notifications.

The C# style allows the user to add or remove event handlers at runtime by assigning to the events of properties of this class. Event handlers can be anyone of a method, an anonymous methods or a lambda expression. Using the C# style events or properties will override any manual settings to the Objective-C Delegate or WeakDelegate settings.

The Objective-C style requires the user to create a new class derived from MonoTouch.UIKit.UINavigationBarDelegate class and assign it to the MonoTouch.UIKit.Delegate property. Alternatively, for low-level control, by creating a class derived from MonoTouch.Foundation.NSObject which has every entry point properly decorated with an [Export] attribute. The instance of this object can then be assigned to the UINavigationBar.WeakDelegate property.

Structure

The MonoTouch.UIKit.UINavigationBar maintains a stack of MonoTouch.UIKit.UINavigationItems. The MonoTouch.UIKit.UINavigationBar displays the UINavigationBar.TopItemMonoTouch.UIKit.UINavigationItem. You can push and pop MonoTouch.UIKit.UINavigationItems using UINavigationBar.PushNavigationItem and UINavigationBar.PopNavigationItemAnimated.

The MonoTouch.UIKit.UINavigationBar is most commonly seen in conjunction with a MonoTouch.UIKit.UINavigationController, which manages the MonoTouch.UIKit.UINavigationBar and pushes and pops the necessary MonoTouch.UIKit.UINavigationItems.

Each MonoTouch.UIKit.UINavigationItem defines left, center, and right subviews. The left and right subviews are expected to be of type MonoTouch.UIKit.UIBarButtonItem, while the center subview by default displays the value of the UINavigationItem.Title property. The center view can be further customized by assigning to the UINavigationItem.TitleView property.

When used with a MonoTouch.UIKit.UINavigationController, the current MonoTouch.UIKit.UIViewController's UIViewController.NavigationItem property is used to manipulate the MonoTouch.UIKit.UINavigationBar, as shown in the following example.

C# Example

          public class MyViewController : UIViewController
          {
             public override void ViewDidLoad ()
             {
                base.ViewDidLoad ();
          
                this.NavigationItem.Title = "NavigationItem.Title";
                this.NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Action, OnAction);
                //...etc....
          

Application developers who wish to customize the behavior of the MonoTouch.UIKit.UINavigationController's uniquely-styled '"Back" button when using a MonoTouch.UIKit.UINavigationController can use the following technique:

C# Example

          public class MyViewController : UIViewController
          {
             public override void ViewWillDisappear(bool animated)
             {
                base.ViewWillDisappear(animated);
                //If `this` not in stack, we've been popped via "Back" button
                if(NavigationController.ViewControllers.Contains(this) == false)
                {
                   Console.WriteLine("Custom behavior");
                }
             }
          }
          

Related content

Requirements

Namespace: MonoTouch.UIKit
Assembly: monotouch (in monotouch.dll)
Assembly Versions: 0.0.0.0